Radio Shack TRS-80 Model 100 Basic Manual page 135

Basic language lab
Hide thumbs Also See for TRS-80 Model 100:
Table of Contents

Advertisement

3
282 270 350 310 255
4
310 250 310 280 260
5
280 280 280 280 270
8
285 290 330 275 258
Clear memory with the NEW command and enter the following program:
10 OPEN "RAM:SALEDA" FOR OUTPUT AS
1
20 FOR
I
=
1
TO 30
30 READ S : PRINT #It S : NEXT I
40 DATA 280t275t346t280t250
50 DATA 300t260t320t300t242
60 DATA 29ZtZ70t350t310tZ55
70 DATA 310tZ50t310t290tZ60
80 DATA 280t280t290t280t270
80 DATA 285t280t330t275t258
Execute this program.
The only thing which appears to happen is that the BASIC prompt
Ok
displays after a second or two. What took place almost instantly, was that the sales
data contained in the DATA statements was written to a RAM file.
List the files by pressing
ern
to confirm that file "SALEDA.DO" has been created.
Line 18 The OPEN statement defines a RAM file with the filename "SALEDA.DO"
and assigns it a file number of 1. Since the file is written to, it is declared an output
file.
Lines 28 • 38 The FOR/NEXT loop repeats 30 times, corresponding to the 30 data
values. Each time through the loop, the next sales value is read from the DATA
statements and then output to file number 1.
Lines 48 .
~
The DATA statements contain the 30 sales values in chronological
order.
Once the RAM file has been created, it can be used repeatedly with a variety of
analysis and reporting programs. For example, you could use a statistics program to
read the data file and compute the mean and median. In fact, the SALEDA. DO file
will be used in the next lesson in just this way.
What you have learned:
Yciu should now be able to read and write data files to either RAM or cassette. Recall
that RAM files are more convenient but use valuable memory. On the other hand,
cassette files require an external device, but allow essentially unlimited data storage.
You also learned how the logical operator NOT may be used to simplify the condition
in an IF statement.
129

Advertisement

Table of Contents
loading

Table of Contents