Reading File Data Using Input - Commodore 1541-II User Manual

Hide thumbs Also See for 1541-II:
Table of Contents

Advertisement

open, close every file you even think might be open before ending a program. If for
example, we always gave our files numbers between 1 and 10, we could close them all
with
9950FORI=lTO10
9960 CLOSE I
9970 GOSUB 59990:REM CHECK FOR DISK ERRORS
9980 NEXT I
(assuming your program includes an error check subroutine like the one in Chapter 4)
READING FILE DATA: USING INPUT#
Once information has been written properly to a diskette file, it may be read back into
the computer with an Input# statement. Just as the Print# statement is much like the Print
statement, Input# is nearly identical to Input, except that the list of items following the
command word comes from a particular file instead of the keyboard. Both statements are
subject to"the same limitations—halting input after a comma or colon, not accepting data
items too large to fit in Basic's Input buffer, and not accepting non-numeric data into a
numeric variable.
FORMAT FOR THE INPUT# STATEMENT
PRINT#file #,variable list
where "file #" is the same file number given in the desired file's current Open statement,
and "variable list" is one or more valid Basic variable names. If more than one data
element is to be input by a particular Input# statement, each variable name must be
separated from others by a comma.
EXAMPLES:
To read back in the grades written with the Print# example, use:
300 FOR CLASS = 1 TO COURSES
310 INPUT# 1 ,GRADE$(CLASS)
320 GOSUB 59990:REM CHECK FOR DISK ERRORS
330 NEXT CLASS
(assuming your program includes an error check subroutine like the one on page 27).
To read back in the address data written by another Print# example, it is safest to
use:
800INPUT#5,NAME$
810 GOSUB 59990:REM CHECK FOR DISK ERRORS
820 INPUT#5,STREET$
830 GOSUB 59990.REM CHECK FOR DISK ERRORS
840INPUT#5,CITY$
850 GOSUB 59990:REM CHECK FOR DISK ERRORS
49

Advertisement

Table of Contents
loading

Table of Contents