How to find the control names on forms

Discussions relating to breakout scripting, .NET and COM programming with Jiwa objects.

How to find the control names on forms

Postby Mike.Sheen » Fri Oct 31, 2008 9:41 am

This comes up a lot - our breakout scripting will often provide you with a "FormObject" - this is the VB6 form which contains all the controls that you see.

The problem is knowing what controls are available - VB6 doesn't expose these controls publicly for things like object browsers to see.

This little script will loop through each control on the form, and write some interesting values out to a text file - there's sometimes a few hundred controls on a form, so this is preferable to a messagebox being displayed for each control.

Where you put this code fragment is up to you - I tend to just put it in the form loaded, and then close and re-open the form. Just don't forget it's there if you do this on a live system, or users may get errors opening forms because it attempts to write to the local C:\ folder.

Code: Select all
Dim WorkStr
Dim Control
Dim fso, f
Dim lTop
Dim lLeft
Dim lWidth
Dim lHeight
Dim lIndex

   FileName = "C:\ControlListing.txt"

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.CreateTextFile(FileName, True)   
   
   f.WriteLine "Control Name, Index, Top, Left, Width, Height"
   
   
   For Each Control In FormObject.Controls      
      On Error Resume Next
      lIndex = ""
      lIndex = Control.Index
      
      lTop = ""
      lTop = Control.Top
      
      lLeft = ""
      lLeft = Control.Left
      
      lWidth = ""
      lWidth = Control.Width
      
      lHeight = ""
      lHeight = Control.Height
      
      f.WriteLine Control.Name & "," & lIndex & "," & lTop & "," & lLeft & "," & lWidth & "," & lHeight
   Next

   f.Close
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Return to Technical / Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron