Disk File Input/Output |
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 |
| MKS$ | 4 bytes |
| 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
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