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.
LINE INPUT # and INPUT # Statement 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.
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
DEFINT A-Z
DIM Total AS LONG
CLS ' Clear the screen
OPEN "class.dat" FOR OUTPUT AS #1 ' Create the required input file
PRINT #1, 98, 84, 63, 89, 100
CLOSE #1
OPEN "class.dat" FOR INPUT AS #1 ' Open the input file just created
DO WHILE NOT EOF(1) ' Do as long as the end-of-file
Count = Count + 1 ' hasn't been reached
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