Failure to Trap Event Compiled BC /w; Needs Line Label or /v (45948)



The information in this article applies to:

  • Microsoft QuickBASIC 1.0
  • Microsoft QuickBASIC 1.01
  • Microsoft QuickBASIC 1.02
  • Microsoft QuickBASIC 2.0
  • Microsoft QuickBASIC 2.01
  • Microsoft QuickBASIC 3.0
  • 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 Q45948

SUMMARY

The /w compiler option produces smaller EXE files, but event checking is done much less frequently than if /v is used.

In programs without line labels or line numbers, event trapping requires the /v (check between statements) compiler option. In programs compiled with the /v option, events are checked before every statement.

If your program is compiled with the /w option, events are checked only when a labeled or numbered line is encountered at run time. As a result, if compiled with the /w switch, your program will never trap an event if it doesn't pass through a statement that has a label or line number.

This information applies to all ON Event GOSUB statements [where Event can be COM(n), KEY(n), PEN, PLAY(n), STRIG(n), or TIMER(n)] for event trapping in Microsoft QuickBasic Versions 1.00, 1.01, 1.02, 2.00, 2.01, 3.00, 4.00, 4.00b, and 4.50 for MS-DOS; Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2; and Microsoft Basic PDS Version 7.00 for MS-DOS and MS OS/2. In QuickBasic 4.00b and later, Basic compiler 6.00 and 6.00b, and Basic PDS 7.00, the ON UEVENT GOSUB and CALL SetUEvent statements were added for user-defined event trapping.

MORE INFORMATION

Code Sample

The following code sample, which requires QuickBasic 4.00b or later, or Basic compiler 6.00 or later, will not trap the user-defined event if compiled with the /w option. To trap the event, either use the /v option or place a line label in the idle loop as shown.
ON UEVENT GOSUB handle:
UEVENT ON
WHILE i$ <> CHR$(27)      'Press escape to exit
  IF i$ = " " THEN        'Press space to cause UEVENT
'linelabel:         'Remove comment at start of line for /w to trap
    CALL SetUEvent
  END IF
  i$ = INKEY$
WEND
END

handle: PRINT "ON UEVENT"
RETURN
				
Note that the command-line compiler has a different name in different versions, as shown.

QuickBasic Versions 4.x and Basic compiler 6.00 and 6.00b and Basic PDS 7.00 compile with BC.EXE, as follows:

BC test/V



QuickBasic Versions 2.x and 3.00 compile with QB.EXE, as follows:

QB test/V;

QuickBasic Versions 1.x compile with BASCOM.EXE, as follows:

BASCOM test/V;


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