collection and objects

Posted on 2005-04-05
Medium Priority
Last Modified: 2012-05-05


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?

Question by:TungVan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 13

Accepted Solution

rettiseert earned 500 total points
ID: 13708517

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

Author Comment

ID: 13708931

thx..it works
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13708972
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question