BUG: Cannot ERASE Arrays in SUBs DIMmed in Main Program (78133)



The information in this article applies to:

  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0
  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0a
  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0b

This article was previously published under Q78133

SYMPTOMS

Any attempt to ERASE an array from within a SUB program will generate an "Invalid function call" error when run from the interpreter, or an "Invalid statement ordering" 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 "Make all arrays static" compile option, the error "Cannot erase static array variables" 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 "Invalid function call" 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 "Invalid Statement Ordering" 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.

Modification Type:MajorLast Reviewed:10/20/2003
Keywords:kbbug KB78133