Sinclair QL User Manual page 115

Hide thumbs Also See for QL:
Table of Contents

Advertisement

In order to sort the file 'phone' into alphabetical order of names we must read It Into
an Internal array, sort it, and then create a new file which will be in alphabetical order
of names.
It is never good practice to delete a file before its replacement is clearly established and
proven correct You should therefore copy the file first, as security, uSing a different name.
The required processes are as follows:
1.
Copy the file 'phone' to 'phone_temp'
2.
Read the file 'phone' Into an array.
3.
Sort the array.
4.
Pause to check that everything IS in order.
5.
Delete file 'phone:
6.
Create new file 'phone:
This is all the program needs to do but the new file should be immediately checked using:
COPY mdv1
phone TO sc r
Any further necessary checks should be carried out then:
DELETE mdv2 phone
COPY mdv1
phone TO mdv2 phone
COPY mdv1 phone TO sc r -
DELETE mdv1_phone_temp
The above operations complete the process of substituting a sorted file for the original
unsorted one in both master and back-up files.
In the following program we Illustrate the passing of complete arrays between main
program and procedure. The data passes in both directions.
In line
40
the array, row, holding the numbers
1,2,3
is passed to the procedure, addsix.
The parameter,
come,
receives the Incoming data and the procedure adds six to each
element The array parameter, send, at this point holds the numbers 7,8,9.
These numbers are passed back to the main program to become the values of array,
black. The values are printed to prove that the data has moved as required.
Some Techniques
SORTING
A
MICRODRIVE FILE
ARRAY
PARAMETERS
MAIN
PROGRAM
[row~back_l_
Screen
Output
PROCEDURE [ o m e - - - _ .
+6 - - - _ .
send~
addsix
L
~
100 REMark Pass Arrays
110 DIM row(3) ,back(3)
120 FOR k = 1 TO 3 : LET row (k) = k
130 addsix row, back
140 FOR k = 1 TO 3 : PRINT
I
back(k)
I
150 DEFine PROCedure addsix(come,send)
160
FOR k = 1 TO 3 : LET send(k)=come(k)+6
170 END DEFine
789
The following procedure receives an array containing data to be sorted. The zero element
will contain the number of items. Note that it does not matter whether the array is numeric
or string. The principle of coercion will change string to numeric data if necessary.
12/84
Program
Output
99

Advertisement

Table of Contents
loading

Table of Contents