List all controls in a VB6 project

I would like to be able to list all the controls in a VB6 project at runtime
keymacAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

learning_t0_pr0gramCommented:
you mean like:


    Dim c As Control
   
    For Each c In Form1
        List1.AddItem c.Name
    Next
   
this will display the name of all controls into a listbox (List1)
0
Shanmuga SundaramDirector of Software EngineeringCommented:
private sub listcontrols
For Each object In Me.Controls
Debug.Print TypeName(object), object.Name
Next
end sub
0
pathakhemantCommented:
' CREATE A NEW PROJECT
' FORM1,LIST1

Private Sub Form1_Load()
      LISTALLCONTROLS
end Sub

PRIVATE SUB LISTALLCONTROLS()
dim Ctl  as Control

List1.Clear
For Each Ctl in Me.Controls
     list1.Additem Ctl.Name
next
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

keymacAuthor Commented:
I know how to get the controls of a form, but I want to get all controls from all forms in the project.
0
Antagony1960Commented:
This will add an underlined entry for each form with an offset list of each control underneath:

Dim f As Form, c As Control
    For Each f In Forms
        ListBox1.Add f.Name
        ListBox1.Add "-------------------------"
        For Each c In f.Controls
            ListBox1.Add "    " & c.Name
        Next
    Next
0
Antagony1960Commented:
^^ Slight correction to that code:

Dim f As Form, c As Control
    For Each f In Forms
        List1.AddItem f.Name
        List1.AddItem "-------------------------"
        For Each c In f.Controls
            List1.AddItem "    " & c.Name
        Next
    Next
0
keymacAuthor Commented:
Dim f As Form, c As Control
    For Each f In Forms
        List1.AddItem f.Name
        List1.AddItem "-------------------------"
        For Each c In f.Controls
            List1.AddItem "    " & c.Name
        Next
    Next
^^^^^^^^^^^^^^^^^^^^^^^^
This is good for forms that have been activated but I want to list all the controls from all the forms activated or not.
0
Antagony1960Commented:
<<This is good for forms that have been activated but I want to list all the controls from all the forms activated or not.>>

Ah, well they don't have to be activated, just loaded.

The only way I think of to determine what controls are on what forms, without loading them first, is to write a project analysis program which opens and examines the contents of the project's .vbp file, parses the form information contained in that, and then opens and examines each form's .frm file, to get their control lists and see if any sub forms are called from within them. Quite honestly, that would be a mammoth task and probably unnecessary as there are dozens of such utilities--many of them free--already available if you search the internet.

But personally, I think I'd just write a routine which loads every form in the project by name and then use the nested loop method I gave you earlier. It's not elegant but it's probably your quickest option to get at the information you want.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.