Multidimensional Arrays
In Access it is possible to create an array with more than one dimension.
Dim myIntegerArray() as Integer ReDim myIntegerArray(7,52)
In the above code, we tell Access to create an array of 364 elements (7×52).
In the code below, we create a 3×5 array, fill certain elements with values and print it to the immediate window.
Sub MultiDimendionalArrays() Dim myIntegerArray() As Integer Dim element As Variant ReDim myIntegerArray(3, 5) 'we create a 3 x 5 array myIntegerArray(0, 0) = 1 myIntegerArray(1, 2) = 2 myIntegerArray(3, 3) = 3 myIntegerArray(2, 3) = 4 myIntegerArray(3, 3) = 5 myIntegerArray(3, 1) = 6 'We fill some of the array elements with values 'Any we don't fill will get a default value of '0 because the array is of type integer For Each element In myIntegerArray Debug.Print element 'here we print the array to the immediate window Next End Sub
The result of running the above code will be:
1 0 0 0 0 0 0 6 0 2 0 0 0 0 4 5 0 0 0 0 0 0 0 0 |
Related Posts
Loops – For Each ArraysWorking With Arrays 1 Arrays
Working With Arrays 2 Arrays