Hardware Reference
In-Depth Information
using a series of
IF
...
THEN
statements so that the desired procedure can be
CALL
ed.
If, for example, the user had pressed the fifth key, the result of the
IF
...
THEN
statement would have been found to be true (all others having been false) and
program execution would be diverted to the procedure named
Closedown
.In
this case, and since the result of the
Closedown
routine is irrevocable, the user
should be given the option of returning to the main menu. Hence the
Closedown
procedure should take the following form:
REM Close down and exit
SUB Closedown
CLS
PRINT "You have selected the CLOSE DOWN option."
CALL Confirm(f%)
IF f% = 1 THEN END
END SUB
As before, the confirmation function returns a flag,
f%
, which is true (non-zero)
if the user presses Y or y but is false (zero) if the user presses N or n. If the
user decides not to continue with the
Closedown
procedure,
END SUB
ensures
that the procedure is abandoned and execution resumes at the statement which
follows the procedure
CALL
. The
WEND
statement then diverts the program back
to the beginning of the main menu selection routine.
QuickBASIC offers a more powerful logical construct which is particularly
useful when making menu selections. The construct is based on
SELECT CASE
and eliminates the multiple use of
IF
...
THEN
. The equivalent
SELECT CASE
menu selection program is as follows:
DECLARE SUB Setparams()
DECLARE SUB Heatcontrol()
DECLARE SUB Pumpcontrol()
DECLARE SUB Printreport()
DECLARE SUB Closedown()
REM Main menu selection
WHILE 1
CLS
LOCATE 3, 36
PRINT "MAIN MENU"
LOCATE 6,30
PRINT "[1] Set parameters"
LOCATE 8, 30
PRINT "[2] Heater control"
LOCATE 10, 30
PRINT "[3] Pump control"
LOCATE 12, 30
PRINT "[4] Print report"
LOCATE 14, 30
PRINT "[5] Close down"
LOCATE 16, 30
PRINT "Option required (1-5)?"
DO
r$ = INKEY$
LOOP UNTIL r$<>""
SELECT CASE r$