CLEAR Causes "Illegal Function Call" after RETURN <linelabel> (44795)



The information in this article applies to:

  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0

This article was previously published under Q44795

SUMMARY

A CLEAR statement causes an "Illegal function call" 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 "Illegal function call" 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 "Illegal function call" 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 "Illegal function call" 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 "Illegal function call"
   END

   KeyHand:
   RETURN ErrorHere

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

Modification Type:MinorLast Reviewed:1/9/2003
Keywords:KB44795