Accessing a Member in a Collection

To access a member in a collection, use the Item method, which takes a single parameter that matches a member's index or key value.

Dim myColors As New Collection myColors.Add "red", "r" myColors.Add "white", "w" myColors.Add "blue", "b"

MsgBox myColors.Item(l) MsgBox myColors.Item("b")

MsgBox myColors.Item(4) 'Generates an error.

If the index or key value of the member is not found in the collection, an error like that in Figure 10.4 is generated.

An error is generated when trying to access a member's key value or index that does not exist.

0 0

Post a comment