GBIC: Collections
The following is reprinted for archival purposes from Gary Beene's Information Center, with permission from Mr. Beene himself.
'Collections are objects which can contain many other objects, not necessarily
'of the same type. Limitation - collections cannot contain UDTs.
Dim MyCollection As New Collection
'Collections have these properties/methods:
..Add 'add an item to the collection
.Count 'number of objects in the collection
.Item 'reference to the object in the collection
.Remove 'removes the item from the collection
'members of a collection have an index and a key
Key 'unique string value
Index 'Long integer between 1 and number of items in the collection
'refer to an item in a Collection in these ways:
MyCollection(Key)
MyCollection(Index)
'or
MyCollection.Item(Key)
MyCollection.Item(Index)
'iterate over a collection in two ways:
For i = 1 To MyCollection.Count
'do something with MyCollection(i)
Next i
Dim X As Object
For Each X In MyCollection
... Do something With X
Next
'set a reference to an object in a collection this way
Set MyVar = MyCollection.Item(Index)
'to remove an item from a collection
MyCollection.Remove "Name"
MyCollection.Remove 2
'to clear a collection
Set MyCollection = Nothing
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.