| Declaration statement that names one or more variables and allocates storage space for them. There is no checking for limits on arrays. You can "read" an array value outside that used in DIM, giving unpredictable results. Always keep track of your array start and end instead of LBOUND and UBOUND for the best results.
Syntax: DIM variable[(subscripts)] AS type
examples:
DIM A AS INTEGER, B(2,5,3,9,2) AS INTEGER DIM S AS STRING DIM Form AS QFORM
Details: Use the optional (subscripts) to declare the size of arrays, up to 5 dimensions. Here are some rules to remember: OK: DIM a AS INTEGER, b AS INTEGER, c AS INTEGER
NOT RECOGNIZED CORRECTLY: DIM a, b, c AS INTEGER (In this case, a and b will be VARIANTs, and only c is INTEGER)
OK: DIM (a, b, c) AS INTEGER
NOT RECOGNIZED CORRECTLY: DIM (a = 1, b = 2) AS INTEGER ' error! (try this instead if you want to write your code compactly) DIM a AS INTEGER = 1, b AS INTEGER = 2
Also, you cannot have one of the variables be an array, while others aren't: DIM (a, b(5), c) AS INTEGER ' incorrect! DIM (a, b, c)(5) AS INTEGER ' correct: a, b and c are arrays
For arrays, the numbers are stored serially by the last DIM subscript.
For example,
DIM b(1,3) AS BYTE
values are stored in memory in this order
b(0,0), b(0,1), b(0,2) , b(0,3), b(1,0) ,
b(1,1), b(1,2), b(1,3) |
|