Hardware Reference
In-Depth Information
Table 6.2 Function and
cursor key numbers for use
in conjunction with the
QuickBASIC KEY(n) statement
3
Enable trapping of the F1 key using the statement:
KEY(l) ON
4
If, at any time (e.g. during some critical process) it is subsequently necessary
to disable F1 key trapping, simply include a statement of the form:
Key to be
Value
trapped
of n
KEY(l) OFF
5
Finally, to temporarily inhibit F1 key trapping but, at the same time remem-
bering whether or not the F1 key has been depressed (so that the event trap
can later be executed when a subsequent KEY ON statement is encountered)
the following statement can be used:
F1
1
F2
2
F3
3
F4
4
F5
5
KEY(l) STOP
For readers who may wish to make further use of QuickBASIC's key event
trapping facility, Table 6.2 gives the requisite numerical values associated
with the other function and cursor keys within the KEY(n) statement.
F6
6
F7
7
F8
8
F9
9
F10
10
Numerical inputs
F11
30
F12
31
Cursor up
11
The simple method of dealing with numerical input involves using a BASIC
statement of the form:
Cursor left
12
Cursor right
13
INPUT "Value required"; n%
Sadly, this line of code will only work properly if the user realizes that a
numeric value is required. Since BASIC cannot assign a letter to a numeric
variable, the program will either crash or assign a value of zero if the user
inadvertently presses a letter rather than a number. Furthermore, it would be
useful to be able to impose a range of acceptable values on the user. The program
should reject input values outside this range, warn the user that his input is
invalid, and prompt again for further input. Again, such a routine would be
ideally coded as a procedure.
The procedure call could typically take the form:
Cursor down
14
prompt$ = "Temperature required"
CALLNumberin(prompt$, 60, 90, num%)
while the procedure itself would be coded along the following lines:
REM General purpose integer numerical input
SUB Numberin (prompt$, min%, max%, num%)
DO
PRINT prompt$;
INPUT num$
num% = VAL (num$)
IF n% <= max% AND n% >= min% THEN EXIT SUB
PRINT "Value outside permissible range!"
LOOP
END SUB
The procedure prints the prompt string ( prompt$ ) and assigns the user's input to
a string variable in order to avoid the program crashing if a letter is inadvertently
pressed. The string is subsequently converted to an equivalent numeric variable
Search WWH ::




Custom Search