Chapter
71
Disk
Files
The file
list.dat
stores the data you input through the aid of
the program, not the program itself. To save the program
above, you must assign it a name. Use the SAVE command as
described in Chapter
3.
For example, SAVE "payroll.bas".
Every time you modify a program, you must save it again
(you can use the same name); otherwise, the original pro-
gram remains on disk, without your latest corrections.
5.
To
access data in the file, reopen
it,
this time in the Input
mode with the letter
I.
For example:
OPEN
"115t.dat"
FOR INPUT
AS
1
opens the file named
1ist.dut
for sequential input, using
Buffer
1.
6.
To
read data from the file and assign it
to
program variables,
use either INPUT# or LINE INPUT#. For example:
INPUT#
1,
N$
reads a string item into N$, using Buffer
1
(the buffer used
when the file was opened).
LINE INPUT#
1,
N$
reads an entire line of data into N$, using Buffer
1.
Sample
Program
10 OPEN
"I",
1,
"1ist.dat"
20 IF EOF(11, THEN 100
30
INPUT#l,
N$
40
PRINT N$
50
GOT0
20
100
CLOSE 1
Updating a Sequential Access File
1.
To
add data to the file, open it in Append mode with the let-
ter A. For example:
OPEN
"A",
1,
"list .dat"
opens the file
1ist.dat
so
that
it
can be extended. The data you
enter is appended to the file
1ist.dat.
69