Error, Reading past end of file

I'm trying to read in a high score table containing 10 names and 10 numbers. On running I get the error "Reading past end of file (8011). What can I do to resolve this issue?


SUB HighScoreTable
REM A Subroutine to read and display the high score table
OPEN #4: name "High score table.txt", CREATE newold, org text, access input
PRINT TAB(0); "Names"; TAB(100); "Winnings";
SET#4: POINTER BEGIN
FOR ReadCounter = 1 TO 10
LINE INPUT #4: NameInput$, Number$
PRINT TAB(0); NameInput$, Number$
NEXT ReadCounter
CLOSE #4
END SUB

Comments

Hi, In your code you are

Hi,

In your code you are writing (PRINT) to the file a total of 4 separate items:
(1) TAB(0)
(2) Name$
(3) TAB(100)
(4) Number$
The next thing you are doing is reading just two items. Worse still you attempting to read those two items with LINE INPUT.

The rules for text files are that you must read them in exactly the same way as you wrote to them.

In your example you wrote a whole line of text e.g.
TAB(0); "Names"; TAB(100); "Winnings";
Therefore you must read a whole line of text e.g.
LINE INPUT #4: line$
The variable line$ will contain:
TAB(0); "Names"; TAB(100); "Winnings";

The basic trouble with doing things this way is that you need to untangle the variable lines into the two variables name$ and winning$

It is so much easier to write your variables one by one e.g.
PRINT #4:name$
PRINT #4:winning$
Now you can read them back e.g.
INPUT #4:name$
INPUT #4:winning$

LINE INPUT is normally used if the line of text contains punctuation such as commas.

If you want general purpose routines for reading and writing to text files see my post of yesterday.

Regards
Big John