276 Part II Programming Fundamentals
Setting Aside Memory
When you create an array, Visual Basic sets aside room for it in memory. The following screen
shot shows conceptually how the 10-element Employees array is organized. The elements are
numbered 0 through 9 rather than 1 through 10 because array indexes always start with 0.
9
8
7
6
5
4
3
2
1
0
Employees
To declare a public two-dimensional array named Scoreboard that has room for two rows
and nine columns of Short integer data, you can type this statement in an event procedure
or at the top of the form:
Dim Scoreboard(1, 8) As Short
Using the syntax that emphasizes the lower (zero) bound, you can also declare the array
as follows:
Dim Scoreboard(0 To 1, 0 To 8) As Short
After you declare such a two-dimensional array and Visual Basic sets aside room for it in
memory, you can use the array in your program as if it were a table of values, as shown in
the following screen shot. (In this case, the array elements are numbered 0 through 1 and 0
through 8 .)
0
0 1 2 3 4 5 6 7 8
1
Rows
Columns
Scoreboard