Basic Example of CALL SetUEvent, ON UEVENT GOSUB Trapping (32164)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0

This article was previously published under Q32164

SUMMARY

The following products support user-defined event trapping with the statements ON UEVENT GOSUB, UEVENT ON, and SetUEvent:

  1. QuickBasic Compiler Versions 4.00b and 4.50
  2. Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2
  3. Microsoft Basic PDS Version 7.00 for MS-DOS and MS OS/2
Microsoft QuickBasic Versions 4.00 and earlier do not support user-defined events.

Below is a short example of how to trap a user-defined event.

MORE INFORMATION

You can cause a user-defined event in a program by executing the CALL SetUEvent statement whenever a desired condition occurs. To CALL the SetUEvent routine in the QuickBasic environment, you must invoke QB.EXE with the /L switch to load QB.QLB. For Basic PDS 7.00 you must start QBX with /L to load QBX.QLB. An .EXE program that CALLs SetUEvent must be linked to QB.LIB because the SetUEvent routine is located in the QB.LIB library provided on the product disk. For Basic PDS 7.00 you must link with QBX.LIB.

The UEVENT ON statement turns on trapping of user-defined events. The < ON UEVENT GOSUB label > statement instructs a program where to go when a user-defined event occurs.

The following example invokes the event handler if the value 5 is accepted from the keyboard:
ON UEVENT GOSUB event1
UEVENT ON
INPUT "enter a number"; a
IF a = 5 THEN CALL setuevent
END
event1:
   PRINT "invoked event handler with value"; a
   RETURN
				

Modification Type:MinorLast Reviewed:1/9/2003
Keywords:KB32164