Q(uick)BASIC Statements: UEVENT
Quick View
UEVENT
An event-trapping statement that enables, disables or suspends event trapping for a user-defined event
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- UEVENT ON
- UEVENT OFF
- UEVENT STOP
Description/Parameter(s)
The effects of the UEVENT statements are like that of other event-trapping statements. When UEVENT ON is executed, the event-trapping routine is enabled. Occurrences of the event trigger execution of the event-handling routine.
When UEVENT OFF is executed, the event-trapping routine is disabled. Any occurrences of the event are ignored.
When UEVENT STOP is executed, the event-trapping routine is suspended. An event occurrence is remembered, and the event-trapping routine performed as soon as a UEVENT ON statement is executed.
Example
See the ⮜ ON UEVENT statement programming example ⮞, which uses the UEVENT statement.
See also:
Syntax
- UEVENT ON
- UEVENT OFF
- UEVENT STOP
Description/Parameter(s)
Usage Notes
- UEVENT ON enables trapping of a user-defined event. A user-defined event is usually a hardware interrupt (although it can be a software interrupt). If a user-defined event occurs after a UEVENT ON statement, the routine specified in the ON UEVENT statement is executed.
- UEVENT OFF disables trapping of a user-defined event. No trapping takes place until another UEVENT ON statement is executed. Events occurring while trapping is off are ignored.
- UEVENT STOP suspends trapping of a user-defined event. No trapping takes place until a UEVENT ON statement is executed. Events occurring while trapping is suspended are remembered and processed when the next UEVENT ON statement is executed. However, remembered events are lost if a UEVENT OFF statement is executed.
- When a user-defined trap occurs (that is, the GOSUB is performed), an automatic UEVENT STOP is executed so that recursive traps cannot take place. The RETURN from the trapping routine automatically executes a UEVENT ON statement unless an explicit UEVENT OFF was performed inside the routine.
- If your program contains event-handling statements and you are compiling from the BC command line, use the BC /W or /V option. (The /W option checks for events at every label or line number; the /V option checks at every statement.) If you do not use these options and your program contains event traps, BASIC generates the error message, "ON event without /V or /W on command line."
- For more information, see Chapter 9, "Event Handling" in the Programmer's Guide.
Example
This example uses the UEVENT and ON UEVENT statements to enable user-defined event trapping. The SetUEvent routine signals a user-defined event, and control is passed to an event-handling routine. This example is a primitive use of the UEVENT statements, which are best suited for interfacing hardware to a computer.
Note: In order to use this program or any user-defined event trapping, you must load the Quick library QBX.QLB using the /L option.
CLS
PRINT "This program asks for 10 numbers between 0 and 9, inclusive."
PRINT "As each number is input, it is evaluated to determine whether"
PRINT "it is odd or even. Odd numbers cause a user-defined event"
PRINT "to occur. Even numbers do not.": PRINT
ON UEVENT GOSUB Event1
UEVENT ON
DO
PRINT "Enter a number --> ";
N = VAL(INPUT$(1)): PRINT N: PRINT
SELECT CASE N
CASE 1, 3, 5, 7, 9
PRINT "An odd number was input causing a user-defined event.";
CALL SetUEvent
CASE ELSE
PRINT "No user-defined event occurred.": PRINT
END SELECT
LoopCount = LoopCount + 1
LOOP UNTIL LoopCount = 10
END
Event1:
PRINT "Now processing the UEVENT. The odd number was"; N
PRINT
RETURN
See also: