Microsoft KB Archive/46182

= Other Event Incorrectly Triggers CALL SETUEVENT/ON UEVENT Trap =

Article ID: 46182

Article Last Modified on 11/21/2006



This article was previously published under Q46182



SYMPTOMS
Due to a software problem, you cannot use the UEVENT trapping in conjunction with any other event trapping in the Basic versions listed below. After CALL SETUEVENT is invoked just once, each subsequent non-user-defined event (such as ON TIMER, ON COM, ON KEY, or ON PLAY) also improperly activates the user-defined event (ON UEVENT GOSUB) trap.



STATUS
Microsoft has confirmed this to be a bug in Microsoft QuickBasic versions 4.0b and 4.5, and in Microsoft Basic Compiler versions 6.0 and 6.0b (buglist6.00, buglist6.00b). This problem was corrected in Microsoft Basic Professional Development System (PDS) version 7.0 for MS-DOS and MS OS/2 (fixlist7.00).



MORE INFORMATION
The problem does not apply to QuickBasic versions 4.0 and earlier because they don't support user-defined event trapping (ON UEVENT GOSUB and CALL SETUEVENT).

Example 1
SETUEVENT improperly activates at the same frequency as the ON TIMER event. This behavior continues to occur until the TIMER OFF statement is used. The problem occurs both in a compiled .EXE program and in the QB.EXE environment. SETUEVENT can be called from another language or from the Basic program itself to reproduce the problem.

The following sample code demonstrates the problem in a compiled .EXE program or in the QB.EXE environment: ' Turn the timer and uevent on: TIMER ON UEVENT ON

' Set up the handler routines for events: ON UEVENT GOSUB ueventhandler ON TIMER(1) GOSUB timerhandler  ' Timer event occurs every 1 second.

'Invoke a user-defined event just once: CALL setuevent PRINT &quot;Press any key to end.&quot; WHILE INKEY$ = &quot;&quot; WEND END ueventhandler: PRINT &quot;This uevent should only occur once.&quot; RETURN timerhandler: PRINT &quot;A timer event occurred.&quot; ' TIMER OFF  'Add this line to work around the problem. RETURN

Example 2
A key trapping event also causes this behavior, for example: ON UEVENT GOSUB UEtrap ON KEY(1) GOSUB F1trap UEVENT ON KEY(1) ON PRINT &quot;F1 is trapped. Press enter to trigger Uevent&quot; WHILE INKEY$ <> CHR$(13): WEND   'F1 key will be trapped CALL SetUevent            'trigger Uevent PRINT &quot;Pressing F1 now will cause both events to fire&quot; WHILE INKEY$ <> CHR$(13): WEND   'Pressing F1 now fires both events END UEtrap: PRINT &quot;UEvent trapped&quot; RETURN F1trap: PRINT &quot;F1 trapped&quot; RETURN

Related Problem
In the QB.EXE environment, simply stopping the execution of the program and commenting out the ON TIMER statement fails to stop the activation of the SETUEVENT event during subsequent program runs. For more information on this separate QB.EXE environment problem, query on the following words:

SETUEVENT and buglist4.50

Additional query words: QuickBas BasicCom buglist4.00b buglist4.50 B_BasicCom

Keywords: KB46182

-

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

© Microsoft Corporation. All rights reserved.