advr.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
DIM Statement Details
  Summary  Details  Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
 DIM [SHARED] variable[(subscripts)] [AS type]
            [,variable[(subscripts)] [AS type]]...
 
 Usage Notes
   ■ The TO keyword provides a way to indicate both the lower and upper
     bounds of an array variable's subscripts. For example, the following
     statements are equivalent if there is no OPTION BASE statement:
 
         DIM A(8, 3)
         DIM A(0 TO 8, 0 TO 3)
         DIM A(8, 0 TO 3)
 
     See: OPTION BASE Statement
 
   ■ Array subscripts can be negative. The TO keyword can be used to specify
     any range of subscripts between -32,767 and 32,767, inclusive. For
     example:
 
         DIM A(-4, TO 10)
         DIM B(-99 TO -5, -3 TO 0)
 
   ■ The amount of memory used by a numeric array is calculated by
     multiplying the number of elements in the array times the number of
     bytes required by the data type of the array. For example, an integer
     array requiring 2 bytes per element can contain twice as many elements
     as a long integer array requiring 4 bytes per element. String arrays are
     limited to almost 64K bytes.
 
   ■ If you use a subscript greater than the specified maximum or smaller
     than the specified minimum, an error message is generated. An error
     message is also generated if the size of the array (bytes of memory
     used) exceeds the limits described above.
 
   ■ The DIM statement initializes all:
     • Elements of numeric arrays to zero
     • Elements of string arrays to null strings
     • Fields of user-defined type variables to zero, including fixed-length
       string elements
     • Fixed-length strings to null strings
 
   ■ Use DIM to set the following properties of an array:
     • Number of dimensions (maximum - 60)
     • Upper subscript value (default - 10 for any array dimension)
 
   ■ Use DIM at the module or procedure level to make the following variable
     declarations:
     • At the module level, declare variables that are available to all
       procedures throughout that module.
     • At the procedure level, within a SUB or FUNCTION procedure, declare
       variables that are local to that procedure; it is acceptable to place
       DIM statements at the beginning of the procedure.
 
   ■ Use DIM with empty parentheses at either the module or procedure level
     to declare dynamic arrays. Use REDIM at the procedure level to actually
     define the number of elements and dimensions in the array.
     See: REDIM Statement
 
   ■ You cannot use DIM to redeclare a dimension for an array variable whose
     size has already been declared. If you attempt to do so, an error
     message is generated.
 
   ■ DIM provides a way to declare variables of user-defined types. For
     example, the following user-defined type is defined at the module level.
     In a module or procedure, the variable TopCard is declared using the DIM
     statement:
 
         TYPE Card                       ' At module level
              Suit AS STRING * 9
              Value AS INTEGER
         END TYPE
 
         DIM TopCard As Card             ' At module or procedure level
 
     See: TYPE Statement
 
   ■ You can also declare arrays of user-defined types. For example:
 
         DIM Deck(1 TO 52) AS Card
 
   ■ The SHARED keyword used with DIM shares variables among all procedures
     in a module. In contrast, the SHARED statement shares variables between
     a single procedure and module-level code. See: SHARED Statement