bas7ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
EOF and INPUT # Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'This example uses the INPUT # statement to read a series of test scores
'from a sequential file, then calculates and displays the average score.
'The program uses the EOF function to determine when the last score has
'been read from the file.
 
DEFINT A-Z
DIM Total AS LONG
CLS
 
'Create the required input file.
OPEN "class.dat" FOR OUTPUT AS #1
PRINT #1, 98, 84, 63, 89, 100
CLOSE #1
 
 
'Open the input file just created.
OPEN "class.dat" FOR INPUT AS #1
 
DO WHILE NOT EOF(1)    'Do as long as the end-of-file hasn't been reached.
    Count = Count + 1
    INPUT #1, Score    'Get a score from file #1.
    Total = Total + Score
    PRINT Count; Score
LOOP
PRINT
PRINT "Total students:"; Count; " Average score:"; Total / Count
END
 
'Sample Output
'
' 1  98
' 2  84
' 3  63
' 4  89
' 5  100
'
'Total students: 5  Average score: 86.8