100
LSET
P$
=
TEL$
110
PUT
1,
CODE'X,
120
GO
TO
30
130
CLOSE
1
The two-digit code that you enter
in
line 30 becomes a record
number. That record number will store the name(s), amount(s) and
phone number(s)
you
enter when lines 50, 60 and 70 are
executed. The record
is
written to the file when BASIC executes
the PUT statement
in
line 110.
After typing this program, SAVE it
and
RUN
it.
Then, enter the
following data:
2-DIGIT
CODE,
0
TO
END?
20
NAME?
SMITH
AMOUNT?
34.55
PHONE?
567-8000
2-DIGIT
CODE,
0
TO
END?
0
BASIC stored SMITH, 34.55, and 567-9000
in
record 20 of file
LISTING.
Accessing
a Direct-Access
File
1.
OPEN the file
in
"0"
mode ("R" can also be used).
Example
OPEN
"D",
1
,"FILE"
,32
2.
Use the FIELD statement to allocate space
in
the buffer for the
variables that will be read from the file.
Example
FIELD
1,
20
AS
N$, 4
AS
A$, 8
AS
P$
3.
Use the GET statement to read the desired record from a direct
disk file into a buffer.
Example
GET
1,
CODE'X.
gets the record numbered COOE% and reads it into buffer
1.
4.
Convert string values back to numbers using the "convert"
functions: CVI for integers, CVS for single-precision values, and
CVO for dOUble-precision values.
Example
PRINT
N$
PRINT
CI,JS<A$)
2-56