Microsoft KB Archive/58609

= ON...GOSUB Example from QB 4.50 Help Gives &quot;Label Not Defined&quot; =

Article ID: 58609

Article Last Modified on 11/21/2006



This article was previously published under Q58609



SUMMARY
The ON...GOSUB example from the QB Advisor online Help system in Microsoft QuickBasic Version 4.50 causes a &quot;Label not defined&quot; error when run without modification. This is not a documentation error, since the preface to the example states &quot;the following program fragment...&quot;, thus implying that the code is incomplete.

The Microsoft Advisor online Help system for QBX.EXE (QuickBasic Extended) in Microsoft Basic Professional Development System (PDS) Version 7.00 for MS-DOS has a complete working example for ON...GOSUB.



ON...GOSUB Example from QB.EXE Version 4.50
The following example, taken from the ON...GOSUB example in the QuickBasic 4.50 online Help system, produces a &quot;Label not defined&quot; error on the ON...GOSUB statement: 'The following program fragment causes program control to branch to 'one of the four subroutines listed, depending on the value of Chval:

DO CLS PRINT &quot;1) Display attendance at workshops.&quot;   PRINT &quot;2) Calculate total registration fees paid.&quot; PRINT &quot;3) Print mailing list.&quot;   PRINT &quot;4) End program.&quot; PRINT : PRINT &quot;What is your choice?&quot; DO      Ch$ = INKEY$ LOOP WHILE Ch$ = &quot;&quot; Chval = VAL(Ch$) IF Chval > 0 AND Chval < 5 THEN ON Chval GOSUB Shop, Fees, Mailer, Progend END IF LOOP END To use the above example, you must define the four GOSUB labels (Shop:, Fees:, Mailer:, and Progend:).

ON...GOSUB Example from QBX.EXE Version 7.00
The following similar example from the QBX.EXE online Help system runs without error: 'This example uses the ON...GOSUB statement to cause program control to 'branch to one of three subroutines, depending on the value of Chval.

CLS   'Clear screen. Attend = 20 Fees = 5 * Attend PRINT &quot;1 Display attendance at workshops&quot; PRINT &quot;2 Calculate total registration fees paid&quot; PRINT &quot;3 End program&quot; PRINT : PRINT &quot;What is your choice?&quot; Choice: DO      ch$ = INKEY$ LOOP WHILE ch$ = &quot;&quot; Chval = VAL(ch$) IF Chval > 0 AND Chval < 4 THEN ON Chval GOSUB Shop, Fees, Progend END IF END Shop: PRINT &quot;ATTENDANCE IS&quot;, Attend RETURN Choice Fees: PRINT &quot;REGISTRATION FEES ARE $&quot;; Fees RETURN Choice Progend: END

Additional query words: QuickBas BasicCom

Keywords: KB58609

-

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

© Microsoft Corporation. All rights reserved.