Microsoft KB Archive/58023

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 17:57, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


Multidimensional Limit for Undeclared (Non-DIMmed) Arrays

Article ID: 58023

Article Last Modified on 11/21/2006



APPLIES TO

  • Microsoft QuickBasic 1.0, when used with:
    • Microsoft MS-DOS 6.22 Standard Edition
  • Microsoft QuickBasic 1.01, when used with:
    • Microsoft MS-DOS 6.22 Standard Edition
  • Microsoft QuickBasic 1.02, when used with:
    • Microsoft MS-DOS 6.22 Standard Edition
  • Microsoft QuickBasic 2.0, when used with:
    • Microsoft MS-DOS 6.22 Standard Edition
  • Microsoft QuickBasic 2.01, when used with:
    • Microsoft MS-DOS 6.22 Standard Edition
  • Microsoft QuickBasic 3.0, when used with:
    • Microsoft MS-DOS 6.22 Standard Edition
  • Microsoft QuickBasic 4.0, when used with:
    • Microsoft MS-DOS 6.22 Standard Edition
  • Microsoft QuickBASIC 4.0b, when used with:
    • Microsoft MS-DOS 6.22 Standard Edition
  • Microsoft QuickBasic 4.5 for MS-DOS, when used with:
    • Microsoft MS-DOS 6.22 Standard Edition
  • Microsoft BASIC Compiler 6.0
  • Microsoft BASIC Compiler 6.0b
  • Microsoft BASIC Professional Development System 7.0



This article was previously published under Q58023

SUMMARY

When you reference an array without first dimensioning it with the DIM statement, it is an undeclared array, and the highest element subscript in each dimension always defaults to 10.

No errors should occur for an undeclared array that has 3 or fewer dimensions, as in the following example:

   X(1,1,1)=0
                

However, if the undeclared (non-DIMMed) array has more than three or four dimensions, such as X(1,1,1,1,1), you may get one or more of the following error messages, depending upon the product version and the number of dimensions referenced:

Subscript out of range
Out of data space
Out of memory
Array not dimensioned
Array too big

Which error message displays depends on whether the array type is string or numeric, how many dimensions you give the undeclared array, whether the program is run in the QuickBasic QB.EXE environment or compiled with BC.EXE, and which version of Basic or QuickBasic is used.

This information applies to Microsoft QuickBasic Versions 1.00, 1.01, 1.02, 2.00, 2.01, 3.00, 4.00, 4.00b, and 4.50 for MS-DOS, to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2, and to Microsoft Basic Professional Development System (PDS) Version 7.00 for MS-DOS and MS OS/2.

MORE INFORMATION

You can easily test to see exactly which errors are generated for all combinations of the criteria above. Note that it is always safe to access any undeclared array as long as it does not have more than 3 dimensions. (Note: Don't confuse dimensions with number of subscripts per dimension.)

Regarding this topic, there is a difference between versions of QuickBasic up to 3.00 and Versions 4.00 and later. In Versions 4.00 and later, undeclared numeric arrays can have 4 or fewer dimensions, and undeclared variable-length-string arrays can have 3 or fewer dimensions. Versions of QuickBasic earlier than 4.00 require all undeclared arrays to have 3 or fewer dimensions. The restrictions that apply to Versions 4.00 and later also apply to Microsoft Basic Compiler Versions 6.00 and 6.00b and Microsoft Basic Professional Development System (PDS) Version 7.00.

The following code examples illustrate the minimum number of dimensions in the undeclared array that are needed to generate an error for specific versions of QuickBasic, Basic Compiler, and Basic PDS:

'QuickBasic Versions 1.00, 1.01, 2.00, 2.01, and 3.00:
PRINT a(1,2,3,4)  ' Numeric array, error for 4 or more dimensions
PRINT a$(1,2,3,4) ' Variable-length string array, error 4 or more dims

'QuickBasic Versions 4.00, 4.00b, 4.50, Basic compiler Versions 6.00
' and 6.00b, and Basic PDS Version 7.00:
PRINT a(1,2,3,4,5) ' Numeric array, error for 5 or more dimensions
PRINT a$(1,2,3,4) ' Variable-length string array, for 4 or more dims.
                

To eliminate the errors, dimension the arrays to the size(s) you want using the DIM statement.

The above limitations need to be added on the page referenced in the Index entry under "Arrays, dimensioning" in the following manuals:

  1. "Microsoft QuickBasic 4.5: Basic Language Reference" for Version 4.50
  2. "Microsoft QuickBasic 4.0: Basic Language Reference" manual for Versions 4.00 and 4.00b
  3. "Microsoft QuickBasic Compiler" Versions 2.0x and 3.00 manual
  4. "Microsoft Basic Version 7.0: Language Reference" manual
  5. "Microsoft Basic Compiler 6.0: Basic Language Reference" for Versions 6.00 and 6.00b



Additional query words: QuickBas BasicCom

Keywords: KB58023