Microsoft KB Archive/44795

= CLEAR Causes &quot;Illegal Function Call&quot; after RETURN =

Article ID: 44795

Article Last Modified on 11/21/2006

-

APPLIES TO


 * 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 Q44795



SUMMARY
A CLEAR statement causes an &quot;Illegal function call&quot; error message after the following steps are performed:


 * 1) CALL a SUBprogram.
 * 2) Trap a key with ON KEY(n) GOSUB.
 * 3) RETURN to a label.
 * 4) Execute a CLEAR statement.



MORE INFORMATION
The reason this condition causes an &quot;Illegal function call&quot; is that the SUBprogram was not exited with END SUB or EXIT SUB. Even though execution is not physically in the SUBprogram when the CLEAR statement is executed, Basic assumes that control is still within the SUBprogram because the information pushed onto the stack during the CALL to the SUBprogram is still on the STACK. The CLEAR statement is not allowed in SUBprograms or FUNCTIONs; therefore, the &quot;Illegal function call&quot; error message is generated.

The fact that the CLEAR statement is not allowed in SUBprograms or FUNCTIONS is documented in the Basic language reference manuals for QuickBasic Version 4.50 and the Basic compiler Versions 6.00, and 6.00b, and the Microsoft Basic PDS Version 7.00, as well as in the on-line help in QuickBasic 4.50 and Microsoft Basic PDS 7.00.

Code Example
The following code sample causes an &quot;Illegal function call&quot; error at the CLEAR statement after you press F1: ON KEY(1) GOSUB KeyHand KEY(1) ON  CALL test END

ErrorHere: CLEAR   'This statement causes &quot;Illegal function call&quot; END

KeyHand: RETURN ErrorHere

SUB test DO : LOOP         'Wait for F1 to be pressed END SUB

Additional query words: QuickBas BasicCom

Keywords: KB44795

-

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

© Microsoft Corporation. All rights reserved.