Chapter
71
Disk
Files
3. To move data into the buffer, use the LSET statement. Nu-
meric values must be converted to 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. For example:
LSET
NS=XS
LSET A$=MKSSCAMT)
4.
To write data from the buffer to a record (within
a
direct ac-
cess disk file), use the PUT statement. For example:
PUT 1, CODE%
writes the data from Buffer
1
to a record with the number
CODE%.
(The percentage sign at the end of a variable speci-
fies that
it
is
an integer variable.)
The following program writes information to
a
direct access
file:
10 OPEN
"R",
1, "li5ting.dat",32
20 FIELD 1, 20
AS
NS,
4
AS
AS,
8
AS
PS
30
INPUT "2-DIGIT CODE,
0
TO END"; CODE%
40
IF CODE%
=
0
THEN 130
50
INPUT "NAME";
XS
60
INPUT "AMOUNT"; AMT
70
INPUT "PHONE"; TELS
80 LSET
NS
=
XS
90
LSET
AS
=
MKS$(AMT)
100 LSET
PS
=
TELS
110 PUT 1, CODE%
120 GOT0 30
130 CLOSE
1
The 2-digit code that you enter in Line 30 becomes a record
number. That record number stores the name(s1, amount(s1,
and phone number(s) you enter when Lines
50,
60,
and
70
are
executed. The record is written to the file when BASIC exe-
cutes the PUT statement in Line 110.
72