Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF (EN)

164 The statement *CAT can be used at any time. However before you can use any of the other file statements you have to open the file. After you have opened a file you can read and write to it as much as you wish. When you have finished with the file you must close it. An analogy may help to make one or two points clearer. The files are all kept in one room and your only method of communicating with them is via five telephone links to five clerks. In addition there is a supervisor who knows which telephone line to use to communicate with the right clerk.

It is the clerk’s job to keep all the files organised and you really have no idea how he or she looks after the files – nor does it matter, so long as the method is efficient. To return to our computer, suppose that we wish to create a file called "DRINKS" in which we list every drink we have ever tried. First of all we have to ask the supervisor to allocate a phone line and clerk to us. The statement X = OPENOUT "DRINKS" will place the number of the channel (telephone line) allocated to the file into the variable X . Next we can ask the user for the names of the drinks using INPUT "WHAT IS THE DRINK CALLED?", D$ and then send the name (held in ) to the clerk to be entered in the file.

Notice how we have to use the variable X to ensure that it is entered in the correct file. PRINT#X,D$ We could then repeat this process until the user replied with the word STOP . The program would look like this: 10 X=OPENOUT "DRINKS" 20 REPEAT 30 INPUT "What is the drink called ", D$ 40 PRINT#X, D$ 50 UNTIL D$="STOP" 60 CLOSE# X When run the program will save the data on cassette (if one is connected). >RUN What is the drink called?WHISKY What is the drink called?VODKA What is the drink called?GIN What is the drink called?WINE What is the drink called?CIDER What is the drink called?TOMATO JUICE What is the drink called?STOP