Microsoft KB Archive/45948

= Failure to Trap Event Compiled BC /w; Needs Line Label or /v =

Article ID: 45948

Article Last Modified on 11/21/2006

-

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 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 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.



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$ = &quot; &quot; 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 &quot;ON UEVENT&quot; 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;

Additional query words: QuickBas BasicCom

Keywords: KB45948

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.