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

365 Reading cassette data files Data, as well as programs, may be recorded on cassette tape. This facility enables the user to keep records of names and addresses (for example) on tape for later use. Since the cassette tape can be started and stopped by the computer it also enables it to record results from experiments over many hours. If the user wishes to read a data file then he or she must first open the file for input. In the process of opening a file the computer will allocate a channel number to the operation. If we wished to read in a list of names recorded on a data file called NAMES then the following statement would get the channel number into the variable X .

100 X=OPENIN("NAMES") Once a file has been opened for input data can be read in from the tape. This can be done in two ways: a chunk at a time (for example a whole name) or a single letter at a time. Data is read in a chunk at a time by using the INPUT#X,A$ statement. This will read the first entry into . To read a single character in use the function A=BGET#(X) . Testing for end of file While reading data in it is useful to test to see if the end of the file has been reached. This is done with the function EOF# . For example:

100 DIM B$(20) 110 Y=1 120 X=OPENIN("NAMES") 130 REPEAT 140 INPUT#X,A$ 150 PRINT A$ 160 B$(Y)=A$ 165 Y=Y+1 170 UNTIL EOF#X 180 CLOSE#X 190 END The program above reads up to 20 names off tape, prints them on the screen and then stores them in an array in memory. Of course if there were more than 20 names on file then the program would fail because the array can only hold 20 entries.