Tutorial by Examples

Items are added to a Collection by calling its .Add method: Syntax: .Add(item, [key], [before, after]) ParameterDescriptionitemThe item to store in the Collection. This can be essentially any value that a variable can be assigned to, including primitive types, arrays, objects, and Nothing.keyO...
Items are removed from a Collection by calling its .Remove method: Syntax: .Remove(index) ParameterDescriptionindexThe item to remove from the Collection. If the value passed is a numeric type or Variant with a numeric sub-type, it will be interpreted as a numeric index. If the value passed i...
The number of items in a Collection can be obtained by calling its .Count function: Syntax: .Count() Sample Usage: Public Sub Example() Dim foo As New Collection With foo .Add "One" .Add "Two" .Add "Three" .Add...
Items can be retrieved from a Collection by calling the .Item function. Syntax: .Item(index) ParameterDescriptionindexThe item to retrieve from the Collection. If the value passed is a numeric type or Variant with a numeric sub-type, it will be interpreted as a numeric index. If the value pas...
Keys Unlike a Scripting.Dictionary, a Collection does not have a method for determining if a given key exists or a way to retrieve keys that are present in the Collection. The only method to determine if a key is present is to use the error handler: Public Function KeyExistsInCollection(ByVal key...
The easiest way to clear all of the items from a Collection is to simply replace it with a new Collection and let the old one go out of scope: Public Sub Example() Dim foo As New Collection With foo .Add "One" .Add "Two" .Add "Thre...

Page 1 of 1