Disk File Input/Output

BASIC-SO

Remember that random disk files are stored as strings. Just as you must convert fields that represent numeric values when you read them (using eVI, CVS, or CVD), so must you convert numeric values to their corresponding strings when writing to a random file, using the MKI$, MKS$, and MKD$ functions. Again, you must be sure to allow for the number of bytes required to store the three numeric data types.

Integer

MKI$

2 bytes

Single-precision value

MKS$

4 bytes

Double-precision value

MKD$

8 bytes

For example, assume that you open a random file and define two fields: the first 2 characters as P$ and the next 4 characters as C$; the first field represents a part number and the second its cost. The following statements open the file, set P$ equal to a variable P A and C$ equal to a variable CO, then write the two values to file number 5:

10OPEN "R", #5, ":F1 :PARTS"

20FIELD #5, 2 AS P$, 4 AS C$

30LSET P$ = MKI$ (PA)

40RSET C$ = MKS$ (CO)

50PUT#5, 1

The part number, of course, must be between -32768 and 32767, and the cost will be accurate to 7 digits.

Two other functions are related to random disk 110: LOC and LOF. LOF returns the number of the last sector in the file; LOC returns the number of the sector that was last read or written.

5~8

Page 40
Image 40
Intel 9800758-02 manual Mki$