Microsoft KB Archive/48727

= PRB: ScrollText & Improper RETURN from ON Event GOSUB Can Bomb =

Article ID: 48727

Article Last Modified on 1/9/2003

-

APPLIES TO


 * Microsoft QuickBasic Compiler for Macintosh 1.0

-



This article was previously published under Q48727



SYMPTOMS
In Microsoft QuickBasic Version 1.00 for the Macintosh, system bombs or machine hangs can result from returning improperly from GOSUB subroutines for event-trapping when the ScrollText MBLC routine is used. This can occur in compiled applications and in the QuickBasic interpreter. Different system bomb ID numbers can result, but the most common one encountered is &quot;System Error ID = 02.&quot;



RESOLUTION
To avoid problems when you perform ON Event GOSUB statements (such as ON MENU GOSUB), be sure to RETURN from handling the event before attempting to handle the next event.



MORE INFORMATION
Below is an example of an incorrectly designed QuickBasic program that does not return properly from an ON MENU GOSUB routine. The program is condensed from a customer's larger program. The problem occurs from doing an ON MENU GOSUB statement followed by a GOSUB to a routine that turns MENU ON (mistakenly), invokes ScrollText, and is improperly exited by trapping the user-defined QUIT menu option.

The program needs restructuring so that MENU remains OFF while handling a MENU event (between the ON MENU GOSUB and the RETURN). Also, the ScrollText routine should be moved to a loop at the main level code so MENU events can be used in proper conjunction. You should also execute DisposeScroll when finished using the ScrollText statement.

The necessary program revisions are not written in the program below. Please refer to the ToolBoxSampler program in the &quot;QB Demos&quot; folder on the QuickBasic 1.00 release disk for a similar working example. ToolBoxSampler polls the MENU function instead of trapping MENU events with the ON MENU GOSUB statement.

Example of Incorrect Programming
To encounter the system bomb, choose the QUIT option under the OPTION One menu two times. This produces a system bomb the first time when run as a compiled application, but in the environment you might have to run it a few times to get a system bomb. DEFINT a-z DIM HILOW$(31) QuitFlag=1 GOSUB restoreall ON MENU GOSUB doMenu: MENU ON WHILE 1 : WEND

doMenu: MenuID = MENU(0) MenuItem = MENU(1) 'SELECT CASE MenuID CLS SELECT CASE MenuID CASE 1 'FILE  menu SELECT CASE MenuItem CASE 1 : GOSUB Quitsub END  SELECT CASE 2 SELECT CASE MenuItem CASE 2 : GOSUB HILOWLIST END SELECT CASE ELSE END SELECT MENU RETURN

HILOWLIST: MENU ON  ' Bad program design: should be no MENU ON here, ' and you can't expect to trap MENU selection events in            ' the ScrollText loop below, since you haven't yet ' RETURNed from the MENU event which got you here. linenum% =0: top%=0:  S&=0:  in%=0:  SS&=0 SetRect scr%(1),3,60,275,270 FRAMERECT VARPTR (scr%(1)) SetRect Bar%(1),274,60,290,270 NewScroll S&,Bar%(1),1,1,20,1: 'verticle QuitFlag=3 WHILE MOUSE (0)<>1 'This Loop is only exited by the Menu Option ScrollText S&,scr%(1),HILOW$(1),top%,31,linenum% WEND RETURN                'This RETURN is never executed.

restoreall: MENU 1,0,1,&quot;File&quot; MENU 1,1,1,&quot;QUIT&quot;:cmdkey 1,1,&quot;Q&quot; MENU 2,0,1,&quot;OPTION ONE&quot; MENU 2,2,1,&quot;OPTION TWO&quot;:cmdkey 2,2,&quot;H&quot; RETURN

hilowend: DisposeScroll S&    WINDOW CLOSE 1 WINDOW 1 RETURN

Quitsub: IF QuitFlag=1 THEN GOSUB restoreall : PRINT &quot;the end&quot; : END IF QuitFlag = 3 THEN QuitFlag=1 : GOSUB hilowend : GOSUB restoreall RETURN

Additional query words: MQuickB SR# S890822-45

Keywords: kbprb KB48727

-

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

© Microsoft Corporation. All rights reserved.