The facility of moving along the Record to the next Field is used in a
‘dynamic’ way. The first value of X in the FOR-NEXT loop of line 80 is 0.
SPACE$ is a’dummy’ field that ‘grows’ in size. The first time round its size
is 0 bytes (since 12*0=0), so the Field BALANCES(O) will be the 4 bytes
immediately after the Field POSTCODES. The Field DATES$S(0) will be the next 8
Note the use of ARRAYS to store the Balance and Date Fields. The second
iteration of the loop will fix SPACES at 12 bytes and so Fields BALANCES(1),
DATES$(1) will be pushed just beyond BALANCESS(0), DATES$(0). The process
continues until the 12 Fields (0) to (11) have been set up.
The total size of the Record is thus 70+(12*12), or 214 bytes. Data can
be set into the BALANCES$(), DATESS() array Fields from loops, or directly as
the program dictates. Again so long as no Data is ‘SET’ into SPACESS, then no
corruption of other Data occurs.
DYNAMIC DATA FILES and AUTOMATIC BACKUP.
It is always good practice to make at least two (separate disk) copies of
all Files, and DATA files are no exception. It is quite easy to make the BASIC
program save Records to Disks on two or more drives during processing.
Another problem that can often arise is that one might wish to run a
certain program on one of.a number of data files. For example I might have my
Callsign files organised as “A-CG.DAT”, "H-M.DAT”, "N-R.DAT” or “S-Z.DAT” .The
problem here is not too great as I could offer a choice of the 4 files, and
open the appropriate one. One program that I wrote needed to access 99
different small DATA files of 2 or 4K bytes each, and so a better method was
140 DIM CLASS(20),
20 INPUT “Which Class (1 to 20). “;CN$
40 REM CHECK ROUTINE HERE – Check ‘CN’ for Errors
50 FNAM$="CLASS"+"CN$"+”. DAT”
60 OPEN “R",£1, FNAM$,78
70 FIELD ete;
When I use Random files, I always like to ‘Initialize’ my Data files
pefore running my Data handling program for the first time (assuming that I
know how many Records the file will contain). There are several reasons for
this. The main reason is that I can then be sure that I know exactly what Data
is in any Field of any Record. If Data is read from an unwritten and un-initialized
record, sometimes peculiar things can happen, since this can
contain any ‘junk’ depending what that part of the disk was used for
previously. I usually set up Fields as all blank, or all ‘Periods’ as these
are convenient for immediate printing. It may sometimes be useful to set up a
– gmall field as a ‘Marker’ to indicate whether the Record is Free or not. There
is scope here for the use of FOR-NEXT loops.
140 REM FILE INITIALIZATION – INITAREA.BAS 06/09/83
20 PRINT CHR$(26):PRINT TAB(20) “AREA FILE INITIALIZATION”
30 FOR X=1 TO 3
40 FNAM$="AREA"+STR$(X)+”. DAT”
50 FOR RN=1 TO 100