Commodore 2040 User Manual page 76

Cbm 5 1/4-inch dual floppy disk drives
Hide thumbs Also See for 2040:
Table of Contents

Advertisement

Lines 160, 180, and 200 cause the stored values on disk to be read and stored in A$, B$,
and C$, respectively.
It
is extremely useful to be able to access a record which is determined during program
operation. The following routine illustrates a procedure to query the operator for a record
number and data and to write the data to the disk file:
100 PRINT "TYPE RECORD NUMBER AND DATA"
105 INPUT R,D$
110 DOPEN#1,"FILE1",DO
120 GOSUB 190
130 RECORD#l,(R)
140 GOSUB 190
150 PRINT#l,D$
160 GOSUB 190
170 DCLOSE#l
180 END
190 IF DS<20 THEN RETURN
200 PRINT DS$
220 STOP
Line 130 positions the file pointer to record number (R), specified by the user. Note that a
variable used in the RECORD command must be enclosed in parentheses.
Line 150 causes the data stored in D$ to be stored on the disk.
The RECORD command may be omitted if the file is to be accessed sequentially, which
saves time during program execution. An example of this occurs when writing a large data
base to the disk file. Assume that the program has already dimensioned D$ as an array
which contains 100 elements. These elements are to be written to the disk in records num-
ber 1 thru 100 of file FILEl. This could be accomplished with the following program
segment:
110 DOPEN#1,"FILE1",DO
120 GOSUB 190
130 FOR 1=1 TO 100
150 PRINT#l,D$(I)
160 GOSUB 190
165 NEXT I
170 DCLOSE#l
180 END
190 IF DS<20 THEN RETURN
200 PRINT DS$
220 STOP
Since the record pointer is automatically set to record 1 when the file is opened, record 1 is
the first record written.
If
no RECORD command is executed the DOS automatically posi-
tions to the next record after each PRINT. Therefore, the contents of D$ will be written to
records 1 thru 100 of the file.
For detailed description of related BASIC commands, refer to chapter 4 of this manual and
the BASIC 4.0 reference manual.
75

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

304040408050

Table of Contents