80-Bus News |
September–October 1983, Volume 2, Issue 5 |
|
|
|
Page 17 of 67 |
|
|
|
---|
cevncecntn et omnes
Vv
To Read and then Write a Random file the steps are as follows :
O.B8«
OPEN the file
Declare the Fields
GET the required Record from Disk, if records already exist, or INPUT the necessary data and build the record.
Process the Fields
PUT the record onto Disk.
Repeat 3 to 6 until all done
CLOSE the File
90 INPUT “Enter CALL to be found. “;CSGNS
100 110 120 150 140 150 160 170 180
‘do some input error checking here. OPEN “R",£1, “RADIOLOG. DAT”, 70 FIELD£1,18 AS NAMES,8 AS CALL$,20 AS TOWNS,16 AS COUNTY$,8 AS DATES
FOR RNUM=X TO Y “X,Y define range of record numbers to be read. GET£1 , RNUM
IF CALL$=CSGN$ THEN GOTO xxxx
NEXT RNUM
PRINT “Record not found. “
CLOSE£1
Line 110 – OPEN’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 120 – Sets up the FIELDS for file £1. Each Field is given a Variable
‘Line 140
name and its length is set. GET’s each Record in turn from the Disk until the search either succeeds or fails altogether.
Line 150 – Looks for match between INPUT data and Disk record data. (N.B. in
this simplified example, Line 150 will probably fail to work since “430CB” 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 160 – Continues looping until record found, or all done. Line 170 – Prints appropriate message. Line 180 – CLOSEs the file.
FIELDS
casement
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.
This is an OCR’d version of the scanned page and likely contains recognition errors.
|
|
|
Page 17 of 67 |
|
|
|
---|