Chapter
10
I
BASIC Kevwords
You may open
a
file for output in only one buffer at a time. Once
you assign
a
buffer
to
a
file with the
OPEN
statement, you can-
not use that buffer in another
OPEN
statement until you close
the
first
file. However, BASIC lets you access the same file
for
in-
put by opening it in different buffers. You may keep several rec-
ords from the same file in memory
for
quick access.
If you open a file for input that does not exist, BASIC returns
a
"File not found" error.
If you open a file
for
output that does not exist, BASIC creates
the file.
If you open a file
for
append that does not exist, BASIC creates
the file and sets the mode
to
RANDOM.
If you open a file for direct access with
a
record length that does
not match the record length assigned
to
the file when it was cre-
ated, an error occurs.
Examples
OPEN
"R",
2,
"test
.dat"
opens the file
test.dat
in direct access mode, using Buffer 2. If
test.dat
does not exist, BASIC creates it on the current drive.
The record length is 128 bytes.
OPEN "LPTI
:I'
FOR
OUTPUT
AS
2
opens the printer
for
sequential output using Buffer
2.
OPEN "A:\PAYROLL\data.ba3"
FOR
INPUT
AS
1
opens the file
databas
in the
PAYROLL
directory on Drive
A
for
sequential input using Buffer 1.
243