Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > File Seeking


Reply
 
Thread Tools Display Modes
  #1  
Old 05-19-2003, 09:29 PM
heyyoutony heyyoutony is offline
Newcomer
 
Join Date: May 2003
Posts: 3
Question File Seeking


Ok, here goes, I have searched all through this forum, and msdn, and I can't find the answer to this question. I was wondering, how to make the program search for certain Strings in a file that is opened by the user, Find that string, and put whatever is behind that string in a array, such as

1. Whatever
2. Whatever
3. Whatever

So, it searches "1." and adds whatever is behind it, in this case ,"Whatever" to Array(0), or Array(1), or Array(2) and so on. If you don't understand it i will try to clarify, Thanks for your Time
Reply With Quote
  #2  
Old 05-20-2003, 12:41 AM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,402
Default

will the period always be between the search target and the data?

i.e.

SearchTarget1.Data1<vbNewLine>
SearchTarget2.Data2<vbNewLine>
...
SearchTargetN.DataN<vbNewLine>
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
Reply With Quote
  #3  
Old 05-20-2003, 11:43 AM
heyyoutony heyyoutony is offline
Newcomer
 
Join Date: May 2003
Posts: 3
Default

No it was just an Example, just wondering how to get it into an array, and I have a second question

How would you do this (Forgive me if what you gave me, answers this)

1. a
2. b
3. c

1. d
2. e
3. f

So, under the first 1. "a" would go in First(0), and the second 1. "d" would go into First(1) and so on until the EOF, or under the First 2. "b" would go into Second(0), and under the second 2. "e" would go into Second(1), would that code that you gave me do that?

Last edited by heyyoutony; 05-20-2003 at 11:50 AM.
Reply With Quote
  #4  
Old 05-20-2003, 02:10 PM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,402
Default

Answering your first post, the simplest way would probably be to load the entire file into a single string. Then, use the Instr function to return the position of the target string (store this number in a variable.) Then, use Instr again to locate the position of the next vbNewLine character string after the current position. Your text will lie between these two positions, so use the Mid Function to fetch it.

You can extend this approach to search for all occurrances of a substring within the file string - just look up the Instr and Mid functions in your help, and search this site for useage hints. You will also want to learn about dynamic arrays to hold the data.
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
Reply With Quote
  #5  
Old 05-20-2003, 02:22 PM
heyyoutony heyyoutony is offline
Newcomer
 
Join Date: May 2003
Posts: 3
Default

Kewl Thanks
Reply With Quote
  #6  
Old 05-24-2003, 01:41 PM
imperio59's Avatar
imperio59 imperio59 is offline
Freshman
 
Join Date: May 2003
Posts: 43
Default

But loading an entire file into a string is very memory consuming ins't it? Imagine a 1 or 2 mb text file, like a month old IRC log (like some of mines are)...


Any ideas for that?
Reply With Quote
  #7  
Old 05-25-2003, 02:21 AM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,402
Default

a few megabytes shouldn't be a problem. I've opened a 30 MByte file this way with no issues. And, I've loaded a 140 MByte file into an array of bytes with no problems. It took 30 seconds or so to load it all in, and move memory from RAM into virtual memory, but, there were no difficulties with it.
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Installation Problem - PLs help urgenlty dpdsouza Installation / Documentation 4 12-02-2004 07:09 PM
File Problems: Files Not Closing etc. Templeton Peck General 5 03-29-2003 11:34 PM
Doesn't want to register! MikeyM Installation / Documentation 5 03-02-2003 08:22 PM
making music continue GrimViper General 3 05-01-2001 10:40 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->