Microsoft KB Archive/42474
Article ID: 42474
Article Last Modified on 11/21/2006
This article was previously published under Q42474
Microsoft QuickBasic Versions 4.00 4.00b and 4.50, Microsoft Basic Compiler Versions 6.00 and 6.00b, and Microsoft Basic PDS Version 7.00 are single-pass compilers. This means that all arrays (static or dynamic) that are to be used within a Basic program must be DIMensioned physically above where they are first used. The exception to this is when they are dynamically declared in a COMMON statement.
The program below demonstrates how the array dimension is unknown when an attempt is made to pass the array to a SUBprogram, even though it is DIMensioned logically before it is used. The resulting error will be "Array not defined" on the CALL statement. This is expected behavior in QuickBasic, Microsoft Basic Compiler, and Basic PDS. The program is as follows:
DECLARE SUB GetStartPos (letterWidth!()) DEFINT A-Z GOSUB DimLetterWidths CALL GetStartPos(letterWidth!()) END DimLetterWidths: REDIM SHARED letterWidth! (128) ' REDIM dimensions a dynamic array. RETURN SUB GetStartPos (letterWidth!()) PRINT UBOUND (letterWidth!, 1) END SUB
If the array is declared as dynamic by a COMMON statement, the error does not occur. Placing the statement COMMON letterWidth!() after the DEFINT A-Z line eliminates the error.
Additional query words: QuickBas BasicCom