Chapter
71
Disk Files
BASIC allocates space for records in numeric order. That is,
if
the first record you write to the file is number 200, BASIC allo-
cates space for records 0 through 199 before storing record 200
in the file.
The maximum number of logical records is 16,777,215. Each
record may contain a minimum of
1
and and a maximum of
3 2
7
68 bytes.
The statements and functions used with direct access files are:
OPEN FIELD LSETiRSET
CLOSE GET PUT
MKD$ MKI$ MKS$
CVD CVI
cvs
LOC LOF
These statements and functions are discussed in more detail in
Chapter 10.
Creating a Direct Access File
1.
To create the file, open it for random access in Random mode
(''R').
For example:
OPEN
"R",
1,
"listing.dat",
32
opens the file named
listing.dat,
gives Buffer
1
direct access
to
the file, and sets the record length
to
32 bytes.
(If
you omit
the record length, the default is 128 bytes.) Remember that
data is passed
to
and from the disk in records.
2. Use the FIELD statement
to
allocate space in the buffer for
the variables that will be written to the file. This is neces-
sary because you must place the entire record into the buffer
before putting it into the disk file. For example:
FIELD
1,
20
AS
N$,4
AS
A$,8
AS
P$
allocates the
first
20 positions in Buffer
1
to
string variable
N$,
the next
4
positions to A$, and the next
8
positions to
P$.
The variables
N$,
A$, and
P$
are now "field names."
71