AMSTRAD cpc 6128 User Instruction page 111

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

Advertisement

32 PRINT " 1 • enter info"
33
PRINT "2. Lis t info"
34 PRINT "3. search"
35 PRINT "4. save info"
36 PRINT "5. Load info"
37 INPUT "enter menu seLection";ms
38 ON ms GOSUB
85 RETURN
125 RETURN
170 RETURN
200 RETURN
40,90,130
As you can see, we've made the program print the menu of options, then take I N PUT
of your selection, putting it into the variable
m
s. The command
0
N
m
s GO SUB in line
38 tells the program that if m s
=
1 then GO to the first SUB-routine line number
(40); if m s =2 then GO to the second SUB-routine line number (9 0), and so on.
As each of the functions are now sub-routines called by the 0 N m s GO SUB command,
they must each have aRE T URN command at the end, hence we have added all those
RE T URN commands above.
Do you remember what the RE TU RN command does?
It
makes BASIC return from
the sub-routine to the point in the program immediately following the appropriate
GO SUB command, so in this case it returns to the instruction after line 38 (which
means that the program will continue at line 40 - the 'enter info' point!) We don't
want that to happen, so we must add:
39 GOTO 32
.... to make the program loop back and display the menu once again. Now RUN the
program again to see how far we've progressed.
OK
let's have a look at the listing ofthe program for a moment. (If the program is still
running, press [ESe] twice.) Type in:
LI ST
This is what you should have so far:
10 REM teLephone book
20 DIM NAME$(10Q1)
30 DIM TEL$(100)
32 PRINT " 1 . enter i nf
0"
33 PRINT "2. Lis t info"
34 PRINT "3. search"
35 PRINT "4. save info"
Chapter 2 Page 6
Beyond Foundations

Advertisement

Table of Contents
loading

Table of Contents