Arrays of Variables
- Last UpdatedJul 18, 2023
- 1 minute read
Arrays of variables allow you to group like variables together, somewhat similar to the grouping of like items in fields of a database. An array is an ordered group of variables of the same name, containing values of the same data type. Individual member elements of the array are identified by a separate index number. Arrays in VBA start their indexing sequence by default at zero. This default base value can be changed in a VBA file module by using the option base statement.
VBA supports single and multi-dimension arrays of variables. VBA creates single dimension arrays by default. Multi-dimension arrays must be specifically declared.
VBA allocates memory space for each element of the array. To minimize the amount of memory used storing arrays, and to minimize the time required to access array data, arrays should not be declared any larger than required.
All elements in an array must be of the same data type. VBA supports arrays of bytes, booleans, longs, integers, singles, doubles, strings, and variants. For details about VBA data types, see VBA Data Types.
Arrays declared in a sub or function procedure have local scope only within that procedure. An array declared outside a procedure has modular (global) scope to all procedures within the project.
Note: VBA arrays cannot be used directly in Plant SCADA command or expression fields. Also, VBA does not support user-defined data types.
Arrays declared (using the dim statement within procedures) do not retain their values between procedure calls in VBA.