By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,559 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

How to move file pointer to the start point?

P: 2
hello

I use visual basic 6.0.

I want to read file twice.

First i read file then i don't know how to move the file pointer to the start point.
i don't want to close file and reopen.

example)
Open InputFileName For Input As #1

While Not EOF(1)
Line Input #1, line
...
Wend

'move file pointer to the start point
'i don't know this

While Not EOF(1)
Line Input #1, line
...
Wend

Close #1

thanks for reading
Jul 19 '07 #1
Share this Question
Share on Google+
5 Replies


P: 38
out of curiosity, why do you need to read the file twice?

Cyberdaemon
Jul 19 '07 #2

P: 2
out of curiosity, why do you need to read the file twice?

Cyberdaemon
I'm developing a verifying program.

for example ) test.txt, 1, 1, 1, "F", 5, 5, 6, "TT" ...

test.txt : file name to verify

1 : line number of the file
1 : start offset of line
1 : end offset of line
"F" : compare data

5 : line number of the file
5 : start offset of line
6 : end offset of line
"TT" : compare data

First i open test.txt file
and search line
and if "Mid (line, start offset, end offset) = compare data " is ture, then print true
and repeat
It's line number is not sorted
It's the reason i read file repeatedly

You have any other good idea?

Tom Lee.
Jul 20 '07 #3

Expert 5K+
P: 8,434
Expand|Select|Wrap|Line Numbers
  1. Seek #1, 1
Pretty sure this is what you're looking for.
Jul 20 '07 #4

Expert 5K+
P: 8,434
As for other ideas, there are probably plenty of things you could do. For one thing, even though the operating system does caching to avoid having to physically read the disk repeatedly, still file IO is fairly "expensive". One way to get around this would be to load each line of the file into an array. You can either do this as you go through doing your comparison, or load it up at the start, all in one go, then just use the array instead of the file.

On the other hand, if you're talking about a small file and speed is not a major concern, you could just close the file and reopen it to start reading again from the beginning. But the Seek will be better than that approach.
Jul 20 '07 #5

P: 1
You da man Killer42!
(Your suggestion worked for me too, and your high IQ is appreciated.)
3 Weeks Ago #6

Post your reply

Sign in to post your reply or Sign up for a free account.