Try...
Do While Not Eof (FileNumber)
'do stuff here like reading in your file
Loop
Good Luck
vb5prgrmr
Posting Virtuoso
1,912 posts since Mar 2009
Reputation Points: 156
Solved Threads: 296
Your issue may be with the multiple line input statements within the loop. I'd throw a breakpoint in and be sure the error isn't coming from the second input line. It may be that the first input line reads, then you acheive EOF, but then you try to do another read without checking EOF again. Blind reads are never good.
Also be sure that your file does not have a blank line at the end of all of your data. If this is the case, then there's your issue.
I am writing a program that allows for people to answer simple questions on Capital Cities of the world. The main program works flawlessly, but I decided to add in a new function that records the user's answers to a question if they get it incorrect and posts it in an external file (named Incorrect.txt) and will then load the file to show the user when the Form "Leaderboard" is loaded.
The actual writing to the file is fine, but when I attempt to read it in from the file, I get the "Input past End of File Error". I have tried to fix this with the "end of file" statements, but it fails to work and according to my teachers, it should.
Here is the code for the read-in to the form.
Private Sub AnswerPaneLoad()
Dim Ansread As Variant
Dim Loading(2, 8) As String
Dim Readin2(2, 8) As String
Open "Incorrect.txt" For Input As #2
For Ansread = 1 To EOF(2)
Line Input #2, Loading(1, Ansread)
Line Input #2, Loading(2, Ansread)
AnswerPane.AddItem Loading(1, Ansread)
AnswerPane.AddItem Loading(2, Ansread)
Next
Close #2
Can anyone help?
Thanks.
TylerSBreton
Junior Poster in Training
89 posts since Oct 2006
Reputation Points: 25
Solved Threads: 3