User`s guide
E-Prime User’s Guide
Chapter 4: Using E-Basic
Page 159
Addressing an element within an array
The individual elements within an array may be accessed or set simply by listing the array name,
and using subscript notation (i.e., the index number enclosed in parentheses) to refer to the
appropriate index. The index of the array includes an integer value for each dimension of the
array. For example, my_array(3) refers to, or identifies the value in the fourth slot in the array
called my_array (given a zero-based numbering system). Given this scheme, data contained
within an array may be used like any other variables:
Assign a value to an array element.
Dim a(10) As Integer
a(1) = 12
Assign a value stored in an array to another variable.
x = a(1)
Use the value of an array element in an expression:
x = 10 * a(1)
4.7.1.3 Assigning Data
When an array is declared using the Dim statement, the elements composing the array are not
initialized. That is, the elements contain no valid information. Before accessing the array
elements, they must be assigned meaningful values. Array elements are assigned values using
an assignment expression (i.e., ArrayName(Index) = Expression).
Dim a(10) As Integer
a(1) = 12
The most efficient method of assigning values to an entire array at one time (e.g., to initialize an
array to consecutive values) is to use a For…Next loop.
Const Size As Integer = 10
Dim a(10) As Integer
Dim x As Integer, i As Integer
For i = 0 To Size-1
a(i) = x
x = x + 1
Next i
Arrays may also be multi-dimensional. Arrays containing more than one dimension are similar to
a spreadsheet-like organization, with different dimensions handling different tables or lists of
information. Multi-dimensional arrays are declared just like one-dimensional arrays, with commas
separating the values specifying the size of each dimension in the array.
Dim multi_array (10, 7, 9) As Integer
The total number of elements held by a multi-dimensional array is equal to the product of the
sizes of the individual dimensions. The example above would result in an array holding 630
elements.