OK, Here is another answer
Thanks for posting the question because it has encouraged me to research a topic I have not bothered too much with in the past.
I have produced the following code in my test application. This is ALL the code there is. Of course, there is an activeX DLL I wrote which provides the classes.
Code:
Option Explicit
Dim myWheel As clsWheel
Private Sub Command1_Click()
Set myWheel = New clsWheel
Dim spoke As clsSpoke
With myWheel
For Each spoke In .Spokes
Debug.Print spoke.Name, spoke.Number
Next
End With
End Sub
I used examples from the Programmers manual (hence Wheel, Spokes, Spoke). Look for Creating Your Own Collection Classes.
The myWheel.Spokes collection displays ONLY the count and Item methods exactly as you want. Object Browser displays only these methods as well.
The code for the classes is below. There are a few things you need to do using the Tools | Procedure Attributes |Advanced menu but I can tell you those after the code if you need.
Code:
' note that these are the class files
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsSpoke"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Dim mNum As Integer
Dim mName As String
Public Property Let Name(newName As String)
mName = newName
End Property
Public Property Get Name() As String
Attribute Name.VB_UserMemId = 0
Name = mName
End Property
Public Property Let Number(newNum As Integer)
mNum = newNum
End Property
Public Property Get Number() As Integer
Number = mNum
End Property
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsWheel"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Dim mSpokes As clsSpokes
Dim mShape As Integer
Public Property Get Spokes() As clsSpokes
Set Spokes = mSpokes
End Property
Public Property Get Shape() As Integer
Shape = mShape
End Property
Public Property Let Shape(newShape As Integer)
mShape = newShape
End Property
Private Sub Class_Initialize()
Set mSpokes = New clsSpokes
End Sub
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsSpokes"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Private mcol As Collection
Public Function NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Attribute NewEnum.VB_MemberFlags = "40"
Set NewEnum = mcol.[_NewEnum]
End Function
Public Property Get Count() As Integer
Count = mcol.Count
End Property
Private Sub Class_Initialize()
Set mcol = New Collection
Dim spoke As clsSpoke
Dim c As Integer
For c = 1 To 10
Set spoke = New clsSpoke
With spoke
.Name = "Spoke" & c
.Number = c
End With
mcol.Add spoke, "Item " & Str(c)
Next
End Sub
Public Function Item(ByVal Index As Variant) As clsSpoke
Attribute Item.VB_UserMemId = 0
Set Item = mcol.Item(Index)
End Function
Note that to use these classes you should copy them into files directly and not attempt to paste them into the VB IDE.
I hope it makes sense. The VB documentation on this topic is excellent so if you get stuck, ask me or see if your documentation helps too :)
Cheers