270 CL0SE#this_one

280 ENDPROC

PROCtake -- names sets up two string arrays which can hold up to 100 names

and telephone numbers. The loop from 120 to 160 takes input from the

keyboard and stores the names and numbers in the two arrays.

PROCmake _file creates the file, which is given a name at line 210. Line 220

opens the file using OPENOUT so that data can be output to it.

BBC BASIC allows you to have up to five files open at the same time. Each file

is given a number by the computer so that it can distinguish between files. This

number is called the channel number. All references to the file are made via

the channel number, so it is vital that it is saved. Line 220 stores the channel

number for the file in the variable this _one.

The loop from lines 230 to 250 writes the data out to the file. Line 240 tells the

computer to print the data out via channel this _one.

The computer needs to be told that there is no more output, so line 260 closes

the channel once all the data has been printed to the file.

Note that running the program only saves the file containing the names and

telephone numbers. The program itself must be saved in the same way you

would save any other program.

A file is of little use unless you can read the information stored in it and the

followings program reads the names and phone numbers in the file back into

memory, and finds the phone number for any friend whose name you have

stored on the file:

10 MODE 135

20 PR0Cread_file

30 PR0Cfind_number

40 END

50 DEFPR0Cread_file

60 DIM friend$(100), numb$(100)

70 PRINT'"What name did you give to"

80 INPUT"your data file",file$

90 that_one=0PENIN(file$)

100 count=0

110 REPEAT

120 count=count+1

130 INPUT#that_one,friend$(count),numb$(count)

140 UNTIL E0F#that_one

150 CLOSE #that_one

160 ENDPROC

170 DEFPR0Cfind_number

C55