"Invalid Character" in Compiler on DIM for Dynamic Array (32417)






This article was previously published under Q32417

SUMMARY

The compiler in QuickBASIC for Macintosh gives an "Invalid character" message for a DIM statement at compile time if an array is dimensioned using a variable or function in the subscript, and the "Make All Arrays Static" compiler option is selected (or DIM STATIC is used). This error occurs because a static array must be dimensioned with a constant or simple constant expression in the array subscript in the DIM statement.

To allow a variable or function in the array subscript in the DIM statement, you must make the array dynamic (by turning off the "Make All Arrays Static" option and by using DIM instead of DIM STATIC).

If some arrays need to remain dynamic while others are static, use the DIM STATIC statement to dimension static arrays and DIM to dimension dynamic arrays, and do not select "Make All Arrays STATIC" (in the "Options..." item of the Run menu).

MORE INFORMATION

The following code gives an "Invalid character" error at compile time only when you select the "Make All Arrays STATIC" compiler option:
   B=180
   DIM X(B)          ' Array must be dynamic.
   DIM Y(SQR(16))    ' Array must be dynamic.
				
The following code always gives "Invalid character" at compile time with or without the "Make All Arrays STATIC" option:
   B=180
   DIM STATIC X(B)        ' Always static when compiled.
   DIM STATIC Y(SQR(16))  ' Always static when compiled.
				
The following code compiles successfully with (or without) the "Make All Arrays STATIC" compiler option selected:
   DIM X(5 * 36)  ' Can be static or dynamic.
   DIM Y(4)       ' Can be static or dynamic.
				
PROGRAMMING NOTES:

Arrays are always dynamic (never static) in the interpreter in QuickBASIC. In the compiler, you can specify static or dynamic arrays.

Note that QuickBASIC for Macintosh offers no REM $ metacommand feature to specify static or dynamic arrays.

Modification Type: Minor Last Reviewed: 1/8/2003
Keywords: KB32417