~
..
Example
OPEN t
"0"
tit
"LISTING"
t
32
opens the file named "LISTING", gives buffer 1 direct access to
the file, and sets the record length to 32 bytes. (If the record length
is omitted, the default
is
256 bytes). Remember that data is
passed to
and
from 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
necessary because
you must place the entire record into the buffer before putting it
into the disk file.
Example
FIELD
1 t
20
AS
N$t
4
AS
A$t8
AS
P$
allocates the first 20 positions
in
buffer 1 to string variable
N$,
the
next four positions to A$, and the next eight positions to
P$.
N$,
A$ and
P$
are now "field names".
3.
To move data into the buffer, use the LSET statement. Numeric
values must be converted into strings when placed
in
the buffer.
To do this, use the "make" functions: MKI$ to make
an
integer
value into a string, MKS$ for a single-precision value, and MKD$
for a double-precision value.
Example
LSET
N$=X$
LSET
A$=MKS$(AMTl
Note: RSET right justifies a string into the buffer. For example, RSET
N$=X$.
4.
To write data from the buffer to a record (within a direct-access
disk file), use the PUT statement.
PUT 1 t
CODEX,
writes the data from buffer 1 to a record with the number CODE%.
(The percentage sign at the end of a variable specifies that it is
an
integer variable.)
The following program writes information to a direct-access file:
10
OPEN
"0"
tit
"LISTING"
t
32
20
FIELD
1 t
20
AS
N$t
4
AS
A$t
8
AS
P$
30
INPUT
"2-DIGIT
CODE t 0
TO
END"
j
CODE'y',
40
IF
CODE%
= 0 THEN
130
50
INPUT
"NAME"
j }{$
80
I NPUT
"AMOUNT"
j
AMT
70
INPUT
"PHONE";
TEL$
80
LSET
N$ = X$
80
LSET
A$ =
MKS$(AMTl
2-55