A collection is an object that represents a set of variants. Each variant in the collection is traditionally of the same data type or class but this in not necessarily true.
A collection is similar to an array in concept (both are sets of scalar values or objects) but is basically different:Collections can refer to their members by a Key (aka identifier. A string.), or by an Index (aka position. A long integer that can be from 1 to the Count property value.). The following examples all refer to a member of the collection:
col1.Item("strKey")
col1("strKey")
col1.Item(lngIndex)
col1(lngIndex)
A recordset is conceptually a collection and also has this additional syntax for accessing its member (i.e. fields):
recordset!field
A collection object has one property and just a few methods (Note that some objects may have collections with other properties and methods.).
.Count. A long integer for the number of objects in the
collection. Read only..Add(NewMember, [NewKey [, [Before | After]]). Add
a new member to the collection. The Before and After parameters adds the
new member before or after an existing member. EG: myCol.Add(myObj, myObj.ID,
before:=1)..Item(KeyOrIndex). The default method..Remove(KeyOrIndex)..Refresh(). This method is only available with certain objects
such as ADO collection objects of Fields, Parameters, and Properties.For an example of how you might implement a collection in your own class, see Property Procedures.
The following list summarizes the steps required to create a collection class.
Employees.Private mEmployees As New Employees.Class_Initialize event procedure, create the Collection object. (If you
want to defer creation of this object until it's needed, you can declare the private variable in
step 2 As New Collection. This adds a small amount of overhead each time the Collection is
accessed.)Public Sub Delete(ByVal Index As Variant) mcolEmployees.Remove Index End Sub
mcol.
Public Function NewEnum() As IUnknown Set NewEnum = mcol.[_NewEnum] End Function
Dim col1 As New Collection
Page Modified: (Hand noted: 2007-09-20 21:17:24Z) (Auto noted: 2007-11-17 06:36:54Z)