Sinclair QL Beginner's Manual page 80

Hide thumbs Also See for QL:
Table of Contents

Advertisement

Suppose that we wish to create the file, numbers, on a cartridge in Microdrive 1. The device name is:
mdv1_
and the appended information is just the name of the file:
numbers
So the complete file name is:
mdv1_numbers
CHANNELS
It is possible for a program to use several files at once, but it is more convenient to refer to a file by an
associated channel number This can be any integer in the range 0 to 15. A file is associated with a
channel number by using the OPEN statement or, if it is a new file, OPEN_NEW. For example you
may choose channel 7 for the numbers file and write:
You can now refer to the file just by quoting the number #7. The complete program is:
100 REMark simple file
110 OPEN_NEW #7,mdv1_numbers
120 FOR number = 1 TO 100
130
PRINT #7,number
140 END FOR number
150 CLOSE #7
The PRINT statement causes the numbers to be 'printed' on the cartridge file because #7 has been
associated with it. The CLOSE #7 statement is necessary because the system has some internal
work to do when the file has been used. It also releases channel 7 for other possible uses. After the
program has executed type
DIR mdv1_
and the directory should show that the file numbers exists on the cartridge in Microdrive mdv1_ .
You also need to know that the file is correct and you can only be certain of this if the file is read and
checked. The necessary keyword is OPEN_IN, otherwise the program for reading data from a file is
similar to the previous one.
100 REMark Reading a file
110 OPEN IN #6, mdv1_numbers
120 FOR item = 1 TO 100
130 INPUT #6, number
140 PRINT ! number !
150 END FOR item
160 CLOSE #6
The program should output the numbers 1 to 100, but only if the cartridge containing the file
"numbers" is still in Microdrive mdv1_.
DEVICES AND CHANNELS

Advertisement

Table of Contents
loading

Table of Contents