The eof function should be used to avoid an "Input past end" error.
FileNum may be any numeric expression. Its value should match the FileNum given in the open statement for the file being checked.
In support of pipes (see open), this function closes the output side of a pipe (if any) and tests for termination of the program to which the pipe is connected. The output pipe is closed to allow the program to stop reading and processing data; therefore this function may used only after all data has been output to the program. The best test for end-of-file from a pipe connected to a program is termination of the program. Thus for pipes, this function really tests for termination of the program as a sure test of end-of-file on the pipe.
open "infile" for input as #1 while not eof(1) input #1, a$ print a$ wendreads strings from the sequential file "infile". Values are read and printed until end of file is reached.
The program
open "pipe: sort -t# +1" as #1 line input a$ while a$ <> "END" print #1, a$ line input a$ wend while not eof(1) if lof(1) then line input #1, a$: print a$ wendcompiled and run with a data file such as "name.number":
$ cat name.number Clive Land #(216) 555-1212 Hugh Ston #(713) 555-1212 Phil Adelphia #(215) 555-1212 Sandy Ego #(619) 555-1212 END $ a.out < name.number Phil Adelphia #(215) 555-1212 Clive Land #(216) 555-1212 Sandy Ego #(619) 555-1212 Hugh Ston #(713) 555-1212 $sorts a list of phone numbers (introduced by pound signs) using the UNIX sort utility. Note that the eof function is used not only to determine that the sort utility has finished sending data, but also to close the output side of the pipe which signals the utility to begin sorting.
If FileNum indicates a file that is open for output only, a "Bad file mode" error occurs.
from The Basmark QuickBASIC Programmer’s Manual by Lawrence Leinweber