'Input Past End of File' Error Persists even with 'EOF' Statements

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2009
Posts: 1
Reputation: Riptr is an unknown quantity at this point 
Solved Threads: 0
Riptr Riptr is offline Offline
Newbie Poster

'Input Past End of File' Error Persists even with 'EOF' Statements

 
0
  #1
Mar 10th, 2009
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.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub AnswerPaneLoad()
  2. Dim Ansread As Variant
  3. Dim Loading(2, 8) As String
  4. Dim Readin2(2, 8) As String
  5.  
  6.  
  7.  
  8. Open "Incorrect.txt" For Input As #2
  9.  
  10. For Ansread = 1 To EOF(2)
  11. Line Input #2, Loading(1, Ansread)
  12. Line Input #2, Loading(2, Ansread)
  13. AnswerPane.AddItem Loading(1, Ansread)
  14. AnswerPane.AddItem Loading(2, Ansread)
  15. Next
  16. Close #2

Can anyone help?

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 835
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 153
vb5prgrmr vb5prgrmr is offline Offline
Practically a Posting Shark

Re: 'Input Past End of File' Error Persists even with 'EOF' Statements

 
0
  #2
Mar 10th, 2009
Try...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Do While Not Eof (FileNumber)
  2. 'do stuff here like reading in your file
  3. Loop

Good Luck
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: 'Input Past End of File' Error Persists even with 'EOF' Statements

 
0
  #3
Mar 10th, 2009
I would use a do until loop. That way the code will only be executed only when there is a line in the text file. That should avoid the error that you mentioned.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim IntCounter as integer
  2. Open "Incorrect.txt" For Input As #2
  3. Do until EOF(2)
  4. Line Input #2, ....
  5. ...
  6.  
  7.  
  8. Loop
Also, I would look at your code inside the loop: Loading(1, Ansread).

I would say that the first element of the array should be Loading(0, Ansread)

The Multi Dimensional arrays as you have them declared actually have 3 first elements (0, 1, 2) and 9 second elements (0, 1, 2, ....., 8). The first value of the Arrays declared as you have coded starts with 0: e.g. Loading (0, 0).

If you want to start with 1, you must be explicit in VB6. But I don't really have enough info from your code to determine if that is your actual problem. This is just a guess. So I couldn't really give you a solid answer here.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim strArray(1 to 2, 1 to 8) as String

Also, you might consider changing your code with regards to your variable Ansread declared as a Variant. You can probably get away with it; but since you're dealing with arrays that will increase with integer or long values, why use a variant variable: use an integer variable. I think you're just asking for trouble there.

But I'm assuming that Ansread has already been determined from code that you didn't include in your post and that it is an integer value.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 89
Reputation: TylerSBreton is an unknown quantity at this point 
Solved Threads: 3
TylerSBreton's Avatar
TylerSBreton TylerSBreton is offline Offline
Junior Poster in Training

Re: 'Input Past End of File' Error Persists even with 'EOF' Statements

 
0
  #4
Mar 10th, 2009
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.

Originally Posted by Riptr View Post
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.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub AnswerPaneLoad()
  2. Dim Ansread As Variant
  3. Dim Loading(2, 8) As String
  4. Dim Readin2(2, 8) As String
  5.  
  6.  
  7.  
  8. Open "Incorrect.txt" For Input As #2
  9.  
  10. For Ansread = 1 To EOF(2)
  11. Line Input #2, Loading(1, Ansread)
  12. Line Input #2, Loading(2, Ansread)
  13. AnswerPane.AddItem Loading(1, Ansread)
  14. AnswerPane.AddItem Loading(2, Ansread)
  15. Next
  16. Close #2

Can anyone help?

Thanks.
Western New England College '08
Computer Science

Programming Lang's:

C, C#, Java, Lisp, MASM, Visual Basic 6
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC