Chapter
71
Disk Files
5.
Convert string values back to numbers using the "convert"
functions: CVI for integers, CVS for single precision values,
and CVD for double precision values. For example:
PRINT
N$
PRINT CVS(A$)
The program may now access the data in the buffer.
The following program accesses the direct access file
list-
ing.dat
(created with the previous program). When BASIC ex-
ecutes Line 30, enter any
valid
record number from
1isting.dat.
This program prints the contents of that record.
10 OPEN
"R",
1,
"ll5tlng.dat",
32
20 FIELD 1,20
AS
N$,4
AS
A$,8
AS
P$
30 RECSIZE%
=
32
50 IF CODE% =0
OR
CODE%
>
(LOF(l)/RECSIZE%) THEN
1000
60 GET
#I,
CODE%
70 PRINT
N$
80 PRINT USING
'I$$#.##";
CVSCA$)
90 PRINT P$: PRINT
100 GOT0 40
1000 CLOSE
1
40 INPUT "2-DIGIT CODE, 0 TO END"; CODE%
After typing this program, save it and run it. When BASIC
asks you
to
enter
a
2-digit code, enter 20 (the record created
through the previous program). Your display should show:
2-DIGIT CODE, 0
TO
END? 20
SM
I
TH
$34.55
567-9000
To update
listing.dat,
simply use LOAD to load the previous
program (the one that created
listing.dat)
and run it.
74