Items - Finding


Collection.Item (index)

References an item and returns a pointer to it
Returns a specific member of a Collection object either by position or by key.


If the value provided as index doesn't match any existing member of the collection, an error occurs.
The Item method is the default method for a collection.
The following lines of code are equivalent:

colMyCollection(1) 
colMyCollection.Item(1)
colMyCollection("key")
colMyCollection.Item("key")

Advanced

Consider the following

for 
   skey = "unique key of the collection"
   set objObject = colMyCollection(skey)

Members can be retrieved using both the index number or a key value
when the key doesn't exist the above line does not reset the objObject to Nothing
therefore objObject keeps its previous value ??


How to determine if an item already exists

You have to loop through all the items to find the one you are looking for ??
Specific items can be returned using the Item method.
If you want to refer to a member of a collection, you can refer to it by its position in the collection, as an index number starting at 1 or by its name as quoted text.


You will obtain a "subscript out of range" error when you try to access an element in a collection that does not exist. Collections in some respects are similar to arrays.


Important

Most of the collections in the Office model are 1-based which means they start at index position 1 rather than 0.



© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext