AMSTRAD cpc 6128 User Instruction page 113

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

Advertisement

100 ON ms GOSUB 120,210,270
110 GOTO 40
120 FOR x=1 TO 100
130 CLS
140 PRINT "press [RETURN] to end input"
150 INPUT;" name''';NAME$(x)
160 IF NAME$(x)='"' THEN 190
170 INPUT" phone";TEL$(x)
180 NEXT
190 PRINT "no more input"
200 RETURN
210 FOR x=1 TO 100
220 IF NAME$(x)='"' THEN 250
230 PRINT NAME$(x);" ";TEL$(x)
240 NEXT
250 PRINT "List finished"
260 RETURN
270 INPUT "find";SEARCH$
280 FOR x=1 TO 100
.
290 IF INSTR(NAME$(x),SEARCH$)=0 THEN 320
300 PRINT NAME$(x);" ";TEL$(x)
310 RETURN
320·NEXT
330 PRINT "name not found"
340 RETURN
That's better. Now on with the program! We'll now add an instruction, so that
whenever you enter some new names and 'phone numbers, the computer will add
them to the existing entries, by placing them in the first element of the array that it
finds to be empty. This time, we'll use the new command LE N to tell us the LENgth of
the string. We'll specify the following:
I F the LENgth of N A ME
$ (
x) is greater than 0, i.e. if there's already an entry in
that element of the array, THE N jump to line 1
80
(which steps to the NE X T element
in the array).
Notice again how similar the above instruction in English is, compared to the
equivalent BASIC instruction just below. I told you that BASIC isn't really a
different language!!!
135 IF LEN(NAME$(x»>0 THEN 180
Such a simple solution isn't it? Problems like these can always be sorted out with your
list of BASIC keywords and a little thought. There's nearly always at least one
command that will satisfy your programming needs, and the more you program, the
more you'll be able to find instant solutions 'off the top of your head'.
Chapter 2 Page 8
Beyond Foundations

Advertisement

Table of Contents
loading

Table of Contents