EXAMPLES:
To close the data
file
#5
used
as
an example on the previous page,
use:
BASIC 7.0: DCLOSE#5
BASIC 2.0: CLOSE 5
In
BASIC 7.0, when the DCLOSE statement
is
used alone
(no#
or file# param-
eters),
it
closes all disk files at once. With a bit
of
planning, the same can be done via a
program loop. Since there
is
no harm in closing a
file
that wasn't open, close every
file
you even think might be open before ending a program. If you always gave your files
numbers between I and 5, you could close them all with
9950 FOR
1=
1 TO 5
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
the last chapter.
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
INPUT#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
thc
PRINT#
examplc,
use:
300 FOR CLASS = I TO COURSES
310 INPUT# I ,GRADE$(CLASS)
320 GOSUB 59990:REM CHECK FOR DISK ERRORS
330 NEXT CLASS
46