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.
Takes a parameter to specify a particular item in the collection can be a number or the name of the object.


Object
Required. An object expression that evaluates to an object in the Applies To list.


Index
Required. An expression that specifies the position of a member of the collection. If a numeric expression, index must be a number from 1 to the value of the collection's Count property. If a string expression, index must correspond to the key argument specified when the member referred to was added to the collection.


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)

Advanced

Consider the following

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

when the key doesn't exist the above line does not reset the objObject to Nothing
therefore objObject keeps its previous value ??


The members of a collection can be iterated using a For Each Next loop


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.



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