Chapter
71
Disk
Files
Creating
a
Sequential Access File
1.
To create the file, open it in Output mode (with the letter
0)
and assign it a buffer number in the range
1
to
15.
For
example:
OPEN
"O",
1,
"li5t
.dat"
OPEN "list.
dat"
FOR
OUTPUT
AS
1
Either form of the syntax for the OPEN statement opens a se-
quential output file named
list.&t
and gives Buffer
1
access
to this file.
2.
To input data from the keyboard into
1
or more program vari-
ables, use either INPUT
or
LINE INPUT. For example:
LINE INPUT, "NAME?
";
N$
inputs data from the keyboard and stores it in variable N$.
3.
To write data to the file, use the WRITE# statement (you
also can use PRINT#, but be sure you delimit the data).
For
example:
WRITE# 1,
N$
writes variable N$ to the file, using Buffer
1
(the buffer used
to
open the file). Remember that data must
go
through a
buffer before it can be written
to
a file.
4.
To ensure that all the data has been written
to
the file, use
the
CLOSE
statement. For example:
CLOSE
1
closes access
to
the file that uses Buffer
1
(the same buffer
used to open the file).
Sample Program
10
OPEN
"O",
1,
"115t.dat"
20
LINE INPUT "ENTER
A
NAME
OR
'DONE' TO END
>
30
IF N$
=
"DONE" THEN
60
40
WRITE# 1,
N$
50
PRINT: GOT0
20
60
CLOSE
1
";N$
68