52
Programming with TIDE
©2000-2008 Tibbo Technology Inc.
dim
x(5)
as
char
x(5)=3
'compiler will determine that this operation will be eccessing an
array element which does not exist!
Multi-Dimensional Arrays
The array in the example above is called a one-dimensional array. This is because
every element in the array has just a single index number. However, we could also
have an array which looks like this:
Index:
0
1
2
3
4
0
15
32
4
100
-30
1
78
15
-3
0
55
2
32
48
97
5
22
3
13
18
9
87
54
4
32
35
79
124
3
5
7
-9
48
8
99
This is called two-dimensional array. Each element in the array is now identified by
an index consisting of two numbers (two coordinates). For example, the element
2, 0 contains the value 32. To create such an array, you would use the following
code:
dim
x(
5
,
6
)
as
char
x(
0
,
0
) =
15
x(
0
,
1
) =
32
x(
0
,
2
) =
4
......
x(
5
,
2
) =
48
x(
5
,
3
) =
8
x(
5
,
4
) =
99
Iterating through such an array would be done using a nested loop for each
dimension in the array. The array above contains only two dimensions, so we
would nest one loop within another. For an array containing six dimensions, we
would have to use six such nested loops. See: