authorArray(index)
Note that index must be an Integer.
You can index with any expression that ends up being an Integer, so this is okay, as long as i was declared an Integer variable earlier:
authorArray(i) = "Twain"
This comes in handy later with loops...
Dim array_name(max_index) As type
Note that the Integer in parenthesis is the maximum index for the array, which is one more than the number of elements, because Visual Basic numbers elements starting from 0, not 1.
With the example array authorArray above, it's alright for me to do this:
MsgBox "Why not read something by " & authorArray(5) & "?"
or this, an assignment:
authorArray(3) = "Angelou"
If you declare an array at the top of your code, right after Option Explicit, it is a global array, i.e. it exists during the whole time your program is running and is available toi all Subs.
If authorArray(7) = "Naipaul" Then ...authorArray("two") = "Melville"
MsgBox "Read any " & authorArray & " lately?"
Case Select authorArray(1.5) ...
Note that authorArray must be declared as a global array for this work.Sub pesterMeAboutReading() Dim i As Integer For i = 0 to 5 MsgBox "Go read some " & authorArray(i) & "!" Next i End Sub