The INPUTTRAP statement establishes characters that, when input as full responses to an INPUT@ statement, force a branch to the specified labels.
Format
INPUTTRAP expr GOTO | GOSUB label1, label2, label3, ... |
Parameter(s)
expr |
An expression evaluating to characters to be searched for in the input. |
GOTO |
Branch to the specified label, without returning. |
GOSUB |
Branch to the subroutine starting at the specified label, and return to the line following the INPUTTRAP statement when a RETURN statement is encountered. |
labeln |
Statement labels to be branched to. If the input is the nth character in expr, the nth label is branched to. |
Description
The INPUTTRAP statement provides an escape from masked input statements. It is used to declare characters which are accepted as responses to an INPUT@ statement, specifying the statement labels to which each character will branch.
The structure of the INPUTTRAP statement is analogous to the ON...GOTO and ON...GOSUB statements, except that the branching variable is taken directly from input instead of by evaluating an expression. The primary purpose for the INPUTTRAP statement is that when an INPUT @ statement is used with format masking, it continues to prompt for input
until the input matches the specified mask. The INPUTTRAP statement allows the programmer to provide an exit from the looping structure of the INPUT @ statement.
If the INPUTTRAP statement is used with the GOSUB keyword, program execution returns to the line following the INPUTTRAP statement when the subroutine is finished, not to the line following the INPUT@ statement.
Example
In this application the user is prompted for a dollar amount. If the user wishes to exit from the program at this point, or would like to start the program over again, the characters E or Q may be entered as a response. The INPUTTRAP statement ensures that if the characters E or Q are entered, the program branches directly to the specified statement labels.
PRINT @(0,3) : "ENTER AMOUNT OF PAYMENT : " : PRINT @(0,23) : "ENTER 'E' IF YOU MADE AN ERROR, 'Q' TO QUIT" : INPUTTRAP "EQ" GOTO ASK.QUESTIONS, EXIT INPUT @(26,3) PAYMENT "L2,$" |
See Also