Does this help.
Module
Sub Test()
Dim clsPersons As CPersons
Dim clsPerson As CPerson
Dim lngIndex As Long
Set clsPersons = New CPersons
clsPersons.Add "Paul"
clsPersons.Add "John"
clsPersons.Add "George"
clsPersons.Add "Ringo"
For Each clsPerson In clsPersons.Persons
Debug.Print clsPerson.Name
Next
Debug.Print "There are " & clsPersons.Count; " people"
Debug.Print "Person 3 is "; clsPersons.Person(3).Name
Set clsPersons = Nothing
End Sub
Class CPerson
Option Explicit
Private m_strName As String
Public Property Let Name(RHS As String)
m_strName = RHS
End Property
Public Property Get Name() As String
Name = m_strName
End Property
class CPersons
Option Explicit
Private m_colPersons As Collection
Public Function Add(Name As String) As CPerson
Dim clsPerson As CPerson
Set clsPerson = New CPerson
clsPerson.Name = Name
m_colPersons.Add clsPerson, Name
Set Add = clsPerson
Exit Function
End Function
Public Function Count() As Long
Count = m_colPersons.Count
End Function
Public Function Person(Index As Variant) As CPerson
On Error Resume Next
Set Person = m_colPersons(Index)
Exit Function
End Function
Public Function Persons() As Collection
Set Persons = m_colPersons
End Function
Private Sub Class_Initialize()
Set m_colPersons = New Collection
End Sub
Private Sub Class_Terminate()
Set m_colPersons = Nothing
End Sub
Bookmarks