Nascom Newsletter |
Volume 3 · Number 3 · August 1983 |
Page 32 of 37 |
---|
including the file opening commands described above, require additional variable names to specify the data (or filename) to be saved or loaded. There are a number of significant restrictions associated with these names in ROM BASIC. Again you should realise that these are associated with the simple BASIC Routine Handler incorporated within NAS-DOS for use with the ROM BASIC. These restrictions are not inherent in NAS-DOS itself, and the Extended BASIC, XBASIC, for example, incorporates ore sophisticated transfer of data between files and variables which are not subject to these restrictions. The main restrictions are as follows:
1. Only simple character strings may be loaded or saved. Numbers must be converted using the STR$ and VAL functions before/after disc access. The variable cannot be an array element. Thus if you have a 20 element numeric array A( ) which you wish to store on disc you would need to use lines of the form
100 FOR I=1 10 20
110 A$= STR$(A(I))
120 A=USR(32),A$
130 NEXT
to save the elements in character string form.
2. While more than one string can be loaded/saved in a single USR( ) statement the strings are stored directly on disc with no separator between them, although after each disc write statement an end-of-record character (0D hex) is output to disc. Therefore in order to read back the data where more than one item has been stored in a record the strings must be of known fixed length otherwise the disc read statement will not be able to determine where one string ends and the next begins. Where the length of the string is variable you will need to fix the length by padding it out to the requied length with additional spaces. Note that this applies where more than one variable is read/written in a single USR call – if only one variable is referenced each time NAS-DOS will use the end-of-record separator which is put in the file after each disc write statement to determine where data which is being read terminates.
These limitations do not affect XBASIC, which allows almost any type of variable to be read or written – see the XBASIC manual for more details on this.
There are essentially two different types of data file which can be saved on disc – at least using NAS-DOS. These are knows as sequential files and random files. We will describe sequential files here and introduce random files. next month we will describe random files in more detail.
Sequential files are very comparable with data written onto magnetic tape. Generally to get any item on the file you must start from the beginning and read (or write) each item in turn until you get to the required point. If you are writing the file you must then write any remaining data. Because the
Page 32 of 37 |
---|