Q(uick)BASIC Routine: SetUEvent
Quick View
SetUEvent
This routine is used in user-event trapping. It sets the BASIC entry point that causes a user-defined event
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Description/Parameter(s)
- SetUEvent sets the BASIC entry point that causes a user-defined event.
Usage Notes
- SetUEvent signals an event for the ON UEVENT event-handling routine.
- The SetUEvent routine is a part of BASIC, and is automatically included in compiled applications or when running QBX with the /L command-line option. Your interrupt-service routine must call SetUEvent; it is the only way to alert your program that the event has occurred. You can call SetUEvent from a non-BASIC language.
- To use the SetUEvent routine in the QBX environment, use any Quick library. To use SetUEvent outside the QBX environment, you do not have to link to a library.
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: