Chapter 11 Using Arrays to Manage Numeric and String Data 277
Working with Array Elements
To refer to an element of an array, you use the array name and an array index enclosed
in parentheses. The index must be an integer or an expression that results in an integer.
For example, the index could be a number such as 5, an integer variable such as num, or
an expression such as num-1. (The counter variable of a For... Next loop is often used .)
For example, the following statement assigns the value “Leslie” to the element with an
index of 5 in the Employees array example in the previous section:
Employees(5) = "Leslie"
This statement produces the following result in our Employees array:
9
8
7
6
5
4
3
2
1
0
Employees
Lesile
Similarly, the following statement assigns the number 4 to row 0, column 2 (the top of the
third inning) in the Scoreboard array example in the previous section:
Scoreboard(0, 2) = 4
This statement produces the following result in our Scoreboard array:
0
0 1 2
4
3 4 5 6 7 8
1
Rows
Columns
Scoreboard
You can use these indexing techniques to assign or retrieve any array element.