Go back to first line of text file

treva26

Registered User.
Local time
Today, 00:42
Joined
Sep 19, 2007
Messages
113
I am opening a text file, counting the number of lines, then processing it.

I am sure there must be a simple way to get back to the first line after counting, but I cant find it so I just close the file and open it again...

Code:
Open "M:\Mining\Unibis\oe404v3.txt" For Input As #1
'count number of lines
count1 = 0
Do While Not EOF(1)
 Line Input #1, ThisString
 Count = Count + 1
Loop
 Total1 = count1
 count1 = 0
Close #1

'now open again to process it
Open "M:\Mining\Unibis\oe404v3.txt" For Input As #1
 While Not EOF(1)
 Line Input #1, ThisString 
 ' do whatever
 Wend
Close #1

Something like:
BOF #1
??

Can anyone help?
 
Last edited:
treva,

Using that method of file operations, I think that you really would be
better off just doing like your example, close then reopen.

If if was a "sequential" file, you could just retrieve a record number,
like record #1.

Why can't it all be parsed on the first pass?
Why can't you table the relevant information on the first pass?

need more info,
Wayne
 
I just need to know the number of lines so that I can display a progress bar as is goes through on the second run processing.

There is no problem the way it is above, it just seems to me there should be a command that goes back to the top.
 
I just need to know the number of lines so that I can display a progress bar as is goes through on the second run processing.

There is no problem the way it is above, it just seems to me there should be a command that goes back to the top.

go back to the top WHY? so you can process it HOW? what are you doing with it exactly?


You can get around moving anywhere initially by just reading the entire thing and then throwing the line number out into your program. Like so:
PHP:
open your stream here

streamObject.Readall

Total1 = streamobject.line //YOU ARE AT THE END HERE FOR READING ONLY
 
Last edited:
if you are opening the file as "for input" then its sequential, and the only way to get back to the top is to close it and reopen.

if you open it as random, and treat it as a file of byte, then you can probably achieve what you want, but its more work to program.

I would do it the first way
 

Users who are viewing this thread

Back
Top Bottom