[Coco] BASIC09 mini-tutorial
Bob Devries
devries.bob at gmail.com
Thu Mar 27 22:54:09 EDT 2008
It's possible to get fairly creative with the ON..GOSUB and ON...GOTO
commands in Basic09 in conjunction with the SUBSTR command.
Here's how:
The SUBSTR command returns the numeric position in a string of the source
string, so you could end up using something like this:
DIM answer:STRING
DIM num:INTEGER
PRINT "Enter Y or N"
INPUT answer
num = SUBSTR(answer,"YyNn")
(* getting more creative here... error trapping!
(* add one to the number in case your user didn't type either Y or N... in
which case num would be 0
ON num+1 GOTO 10, 20, 30, 40, 50
END
10 PRINT "WRONG! Please type Y or N"
GOTO 0
20 PRINT "You typed 'Y'"
END
30 PRINT "You typed 'y'"
END
40 PRINT "You typed 'N'"
END
50 PRINT "You typed 'n'"
END
It's possible to combine two lines above like this:
ON SUBSTR(answer,"YyNn")+1 GOTO 10, 20, 30, 40, 50
Note that you MUST have a line number in the ON...GOTO command for each
possible outcome of SUBSTR.
--
Regards, Bob Devries, Dalby, Queensland, Australia
Isaiah 50:4 The sovereign Lord has given me
the capacity to be his spokesman,
so that I know how to help the weary.
website: http://www.home.gil.com.au/~bdevasl
my blog: http://bdevries.invigorated.org/
More information about the Coco
mailing list