I use the tipical function:
....
Open file For Input As #1
...
ecc...

to reading txt file line by line.

But instead to init the redaing line by line...

1) I need to find, in position mid(line, 1,8), the string INIT0000 and strat the reading of lines from here
2) stop the reading of line from file wehen the code found in mid(line, 1,8), the string INIT0001

please a fast method to find the first line because have peraphs 2.300.000 of lines in original txt file

note:
no possible duplicate string in position mid(line, 1,8)

while left(line, 8) <> "INIT0000"
   READ NEXT LINE
wend
do
   PROCESS LINE
   READ NEXT LINE
while left(line, 8) <> "INIT0001"

hummmmmmm....

Have you see to teh end of my post:

"please a fast method to find the first line because have peraphs 2.300.000 of lines in original txt file2

is this the best and fast method?

Edited 5 Years Ago by sal21: n/a

hummmmmmm....

Have you see to teh end of my post:

Maybe I stopped reading after the horrible misspelling of typical... :icon_wink:

is this the best and fast method?

Are you making a challenge? Best and Fast are rarely if ever the same method.

I guess you had better explain why my suggestion is no good. Do you have a better solution?

There really isn't any super quick way to do what you want...

If the file is line based then you either have to scan through the file sequentially using LineInput

Or, open the the file, I believe in binary mode, and SEEK to a given position.

Here's the problem, using Line Input the File System finds all your End Of Lines (EOL) and gives yous a nice "line at a time" package...

With a File Open method that allows SEEK you can divide and conquer, say SEEK to the middle and see what the INIT number is, assuming that *they* are sequential.

(This method works really good with Fixed Format Files, but it gets tricky when your lines are of variable length.)

But, once you SEEK to a given position *YOU* have to write the code to find the next EOL character and then create a line in your buffer the check for the String in question.

Not impossible...

But, you will have to take your existing code and get a little more creative...

If you check around the middle and you are too far into the file. You then set your Working "End Of File" number to where you are and check between where you are and the Begining of File...

If you are not far enough into the file you use where you are and go halfway to the physical end of your file.

In this way you divide and conquer the file until you are close enough to find your first search string.

Assuming that the strings are in the file sequentially, you could then search using the same method starting from where you found the first search string.

You could even create a table as you go, maybe a hidden form with an MSFlexGrid, as to what "INIT" string was found where you've already been.

That way, if your initial test is still before the second search string you have a "quicker" starting point (possibly) than simply starting a new divide and conquer from where you found the first string.

Let me know if this makes sense?

This article has been dead for over six months. Start a new discussion instead.