• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

collection and objects


hi,

I have a collection variable: Private mControlCollection As VBA.Collection

What I store in that collection is CButton and CLabel objects. For example,

------------------------------------------------------------------------------------------------------------------------------------
Set oButton = New CButton
    oButton.ButtonType = "Formal"
    oButton.CControl_ControlLabel = "Admin"
    oButton.CControl_PositionX = 100
    oButton.CControl_PositionY = 100
    oButton.CControl_Width = 125
    oButton.CControl_Height = 45
    oButton.CControl_Hidden = False
mControlCollection.Add oButton    
Set oButton = Nothing

Set oLabel = New CLabel
  oLabel.LabelType = "Formal"
  oLabel.CControl_ControlLabel = "Clock"
  oLabel.CControl_PositionX = 200
  oLabel.CControl_PositionY = 100
  oLabel.CControl_Width = 125
  oLabel.CControl_Height = 25
  oLabel.CControl_Hidden = False
mControlCollection.Add oLabel
Set oLabel = Nothing

------------------------------------------------------------------------------------------------------------------------------------
So oButton instance is stored in index 0, oLabel is stored in index 1, etc...

Later on, when I need to access object in mControlCollection, how do I know if this object is of type CButton or CLabel?

Is there a way to know it?

Thanks
0
TungVan
Asked:
TungVan
1 Solution
 
rettiseertCommented:
Try

If TypeOf mControlCollection(1) is CLabel then
   MsgBox "Is Label"
ElseIf TypeOf mControlCollection(1) is CButton then
   MsgBox "Is button"
End If
0
 
TungVanAuthor Commented:


thx..it works
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Or something like...

Dim c As Control
For Each c In mControlCollection
    Select Case TypeName(c)
        Case "Label"

        Case "CommandButton"

        Case "TextBox"

        ' etc....

    End Select
Next c
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now