Random access files
AMOS Professional takes full advantage of the second type of file used by the Amiga. Random
access files are extremely useful, because they allow the programmer to access data stored on a
disc in any random order. A random access file is made up of units of data called "records", and
each record has its own identification number. Every record can be split up into as many smaller
sections as required, with every section becoming a "field". Each field is used to hold a single
item of data.
The main difference between sequential files and random access files is that you must tell AMOS Professional the maximum size of a field in advance, before you can make use of it.
A field can hold many forms of data, like a password, an invoice number or even a literary quotation. Supposing you want to create an electronic phone book. You could choose the following fields, with the following maximum number of characters in each:
Field Max. length SURNAME$ 20 F1RSTNAME$ 15 TEL$ 10
Once the fields have been planned, the structure for your electronic database can be set up using the following commands.
OPEN RANDOM
instruction: open a channel to a random access file
Open Random channel,filename$
This command is used to open a channel to a random access file, like this:
X> Open Random 1,"ADDRESS"
FIELD
instruction: define a record structure
Field channel,length1 As field1$,length2 As field2$
X> Field 1,20 As SURNAME$,15 As F1RSTNAME$,10 As TEL$