Microsoft KB Archive/31888

= &quot;Subprogram Already in Use&quot; with Recursive SUB CALL =

Article ID: 31888

Article Last Modified on 11/21/2006



This article was previously published under Q31888



SUMMARY
The message &quot;Subprogram Already in Use&quot; (error 36) is generated when trying to recursively call a STATIC subprogram in an interpreted or compiled program. This is because the STATIC argument must be removed from the SUB statement to make it a dynamic subprogram, which can then be called recursively.

Any attempt to call a dynamic subprogram in the interpreter will give a &quot;Missing STATIC in SUB statement&quot; message. The Macintosh QuickBASIC Interpreter does not support dynamic subprograms (i.e., recursive subprogram calls). Only compiled programs support recursive subprogram calls.



MORE INFORMATION
Both the compiler in QuickBASIC and the older Microsoft BASIC Compiler Version 1.00 for Apple Macintosh support recursive, dynamic SUBprogram CALLs.

The interpreter in QuickBASIC and the Microsoft BASIC Interpreter Versions 2.00, 2.10, and 3.00 for the Apple Macintosh do not support SUBprogram recursion, and require the STATIC argument on the SUB statement.

The program below contains a recursive (dynamic) subprogram which calls itself five times. If this program is executed in the Interpreter, the error will occur. As a compiled program, the error does not occur.

The following is a code example: DEFINT A-Z PRINT &quot;OUTPUT: &quot; CALL RECURSION(5) SUB RECURSION(5)    ' Dynamic subprogram IF MAX <> 0 THEN FOR I=1 TO MAX PRINT I;    NEXT I     PRINT MAX=MAX-1 CALL RECURSION(MAX)  ' calls itself until max = 0 END IF

END SUB This is the output of the program: OUTPUT: 1 2  3  4  5 1  2  3  4 1  2  3 1  2 1

Additional query words: BasicCom MQuickB

Keywords: KB31888

-

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

© Microsoft Corporation. All rights reserved.