80-Bus News

  

September–October 1983 · Volume 2 · Issue 5

Page 17 of 67

To Read and then Write a Random file the steps are as follows :

  1.   OPEN the file
  2.   Declare the Fields
  3.   GET the required Record from Disk, if records already exist, or INPUT the necessary data and build the record.
  4.   Process the Fields
  5.   PUT the record onto Disk.
  6.   Repeat 3 to 6 until all done
  7.   CLOSE the File

e.g.



Line 110OPEN’s the file, declares it as RANDOM, and describes it as File £1 until it is closed. The name of the Data file to be known as File £1 is RADIOLOG.DAT and it uses Records of 70 bytes.
Line 120Sets up the FIELDS for file £1. Each Field is given a Variable name and its length is set.
Line 140GET’s each Record in turn from the Disk until the search either succeeds or fails altogether.
Line 150Looks for match between INPUT data and Disk record data. (N.B. in this simplified example, Line 150 will probably fail to work since “G30CB” does NOT equal “G30CB   “. To work correctly, the trailing blanks would have to be removed, or the INPUT callsign padded out to 8 characters with blanks.
Line 160Continues looping until record found, or all done.
Line 170Prints appropriate message.
Line 180CLOSEs the file.

FIELDS

Although it is possible to use the Data in the Fields directly, as in line 150 above, it is normal practice to ‘move’ the Data out of the Field variable into some other variable for processing. There are several reasons for this:–

  1. The Field data will contain leading or trailing blanks which can lead to unreliable results when Processing or Printing Data.
  2. Numeric data is stored in Fields as Strings. It must be converted back to numeric form for calculations.
  3. Integers are stored as 2 Byte Fields, Single Precision as 4 Bytes, Double Precision as 8 Bytes.
  4. It is often convenient to have the origional Field in uncorrupted form during processing.
Page 17 of 67