Microsoft KB Archive/78133

= BUG: Cannot ERASE Arrays in SUBs DIMmed in Main Program =

Article ID: 78133

Article Last Modified on 10/20/2003

-

APPLIES TO


 * Microsoft QuickBasic Compiler for Macintosh 1.0
 * Microsoft QuickBasic Compiler for Macintosh 1.0
 * Microsoft QuickBasic Compiler for Macintosh 1.0

-



This article was previously published under Q78133



SYMPTOMS
Any attempt to ERASE an array from within a SUB program will generate an &quot;Invalid function call&quot; error when run from the interpreter, or an &quot;Invalid statement ordering&quot; error when compiled. The problem occurs under the following conditions:


 * The array is a dynamic array.
 * The array is dimensioned in the main program.
 * The array is passed as an argument to a SUB program or is in a SHARED statement within the SUB program.
 * The array is erased within the SUB program.

The problem does not occur in the interpreter if SHARED follows the DIM statement for the array and the SHARED statement is removed from the SUB.

When compiled with the &quot;Make all arrays static&quot; compile option, the error &quot;Cannot erase static array variables&quot; is correctly generated at compile time.

Microsoft has confirmed this to be a bug with the binary and decimal versions of Microsoft QuickBasic versions 1.0, 1.0a and 1.0b for the Macintosh. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



MORE INFORMATION
When run in the interpreter, the following code generates an &quot;Invalid function call&quot; error on the ERASE statement. Note that in the interpreter, all arrays are dynamic and all SUBs must be declared as STATIC. When compiling, the following code generates an &quot;Invalid Statement Ordering&quot; error on the ERASE statement.

Example 1
In this example, the array a%, which is dimensioned in the main program, is made accessible to the subprogram by the SHARED statement: DIM a%(30)                      'type of array does not matter CALL asub END

SUB asub STATIC SHARED a% ERASE a% END SUB

Example 2
In this example, the array a% is passed as an argument to the subprogram: DIM a%(30)                      'type of array does not matter CALL asub(a%) END

SUB asub (a%) STATIC ERASE a% END SUB A possible workaround to the problem is to ERASE and DIM the array before making the call to the SUB. If the ERASE is needed in the middle of a SUB, divide the SUB into two SUBs, the first of which returns to the main program where the array can be ERASEd.

Additional query words: MQuickB 1.00 1.00a 1.00b

Keywords: kbbug KB78133

-

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

© Microsoft Corporation. All rights reserved.