EasyManua.ls Logo

Commodore 2031 - Creating a Relative File

Commodore 2031
98 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
size and the DOS will position to the next record in sequence. If the print
statement contains less characters than the record size, the remaining positions
within that record will be filled with nulls. Consequently, when positioning to a
record for input the EOI signal is generated from the DOS to the computer when
the last non-zero is transmitted. Should the programmer desire to store binary
information, a record terminator such as carriage return will have to be used and
the record size is increased by one character to accommodate the terminator.
While the DOS is generating new data blocks for relative files, the requested
record number is compared to the number of data blocks left on the diskette. If
the resulting number of data blocks is greater than what is left on the diskette,
then error 52 -file too large- is generated.
CREATING A RELATIVE FILE
The following examples apply only to those users equipped with BASIC 4.0. In
terms of hardware, this means a 4000 or 8000 Series PET or CBM must be used
as the computer.
When a relative file is opened for the first time, the file should be initialized
by the programmer to allow for faster subsequent access, and to assure that the DOS
reserves sufficient space on the diskette for future data. A simple program to
perform such initialization is illustrated below:
110 DOPEN#1,”FILE1”,D0,L50
120 GOSUB 190
130 RECORD#1,100
140 GOSUB 190
150 PRINT#1,CHR$(255)
160 GOSUB 190
170 DCLOSE#1
180 END
190 IF DS<20 THEN RETURN
200 PRINT DS$
210 IF DS=50 THEN RETURN
220 STOP
In the preceding example, line 110 creates a file with the name FILE1 and a
record length of 50.
Lines 120, 140, and 160 cause the error handling subroutine to be executed. It is
good programming practice to check the error channel after each disk-related
operation.
64

Table of Contents

Other manuals for Commodore 2031

Related product manuals