AMSTRAD cpc 6128 User Instruction page 114

Integrated computer/disc system
Hide thumbs Also See for cpc 6128:
Table of Contents

Advertisement

Now to the matter of saving the contents of the variables so that they can be loaded
back in when the program is run. Part 7 of the Foundation course explained how to
save the program itself, using the S A V E command. However the program itself is
only a framework which lets the variable values be put in (at the keyboard) and taken
out (at the screen). When you S A V E the program, you are saving only that
framework, not the values of the variables.
Hence we must write a section of program that will save the values of the variables
onto disc. We do this by creating a separate 'data file'.
First we 0 PEN an 0 U Tput file and specify a name for it such as "d a
t
a". Then we
WRIT E the values of the variables N A ME $ (x) and T E L$ (x) from 1 to 100, into
the file, and finally we CL 0 SE the 0 U Tput file and RE T URN to the menu. Let's add it
to the program from line
350
onwards. To save us typing in each new line number,
we'll use the command:
AUTO 350
., .. which will start AUT Omatic line numbering from the required line:
350 OPENOUT "data"
360 FOR, x=1 TO 100
370 WRITE #9,NAME$(x),TEL$(x)
380 NEXT
390 CLOSEOUT
400 PRINT "data saved"
410 RETURN
After you have typed in line
410
and pressed [RETURN], press [ESC] to stop the
AUT Omatic line numbering.
Now we need to add an extra number to the list of numbers in the 0 N m s GO SUB
command in line 1
00.
This is because we have added another option for the menu to
select. Therefore E D I T line 1
00
to add this extra number:
100 ON ms GOSUB 120,210,270,350
Now, whenever you select menu option number 4, the program will save all the
information that you entered, onto disc.
Notice that in line 3
70,
where the program W R I T E s the values of N A M E
$ (
x) and
T E L
$ (
x ) onto disc, the expression
#
9 is used after the word W R I T E. The
#
sign is a
'stream director', in other words, it tells the computer which 'stream' to send the data
to. The computer has 10 streams:
Directing data to streams 0 to 7
(#
0
to
#
7) will result in it appearing on the screen
because streams
#
0
to
#
7 are 'screen streams' or WIN DO W s.
Beyond Foundations
Chapter 2 Page 9

Advertisement

Table of Contents
loading

Table of Contents