Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving ALL properties and values for unknown control type! 2

Status
Not open for further replies.

thesleepylizard

Programmer
Mar 18, 2002
41
AU
Hi, here's the scenario. I have a subroutine:

Code:
Public Sub DumpProperties (c as Control)

As the name of the sub suggests, I want to be able to dump all of the properties for "c" into, say, the debug window.

I imagine the code would be something like:

Code:
Dim i as long
for i = lbound(c.GetProperties) to ubound(c.GetProperties)
    debug.print c.GetProperties(i).Name + ", " + c.GetProperties(i).Value
next i

You see what I'm trying to do? GetProperties doesn't exist, of course, but I'm sure there would be something like this. I'm just not sure what it is! Does anyone else know how this is possible?

Thanks for your time,
-Sleepy
 
You might be sure, but it isn't actually that straightforward - although it is possible. The following example is far from complete (only really returns values for simple properties, those that return a string or a number, no error checking, etc.), but it should point you in the right direction. Note that the technique illustrated is not limited to controls; you can also use it against classes...

Firstly you'll need to add a reference to TypeLib Information (this is the library used by VB's object browser). Then add a form and drop on a command button and, say, a text box:
[tt]
Option Explicit

Private Sub Command1_Click()
getProperties Form1.Text1
End Sub


Public Sub getProperties(ctlControl As Control)
Dim myTLI As TLIApplication
Dim myII As InterfaceInfo
Dim myMI As MemberInfo
Dim PropertyString As String


Set myTLI = New TLIApplication

Set myII = TLI.InterfaceInfoFromObject(ctlControl)

For Each myMI In myII.Members
PropertyString = ""
If myMI.InvokeKind = INVOKE_PROPERTYGET Then ' Only bother with properties that return values
PropertyString = myMI.Name + " = "
If myMI.ReturnType.VarType <> VT_I2 And myMI.ReturnType.VarType <> VT_EMPTY And myMI.ReturnType.VarType <> VT_DISPATCH Then 'ignore some of the tricker types, as they require different Invoke calls
PropertyString = PropertyString + CStr(myTLI.InvokeHook(Form1.Text1, myMI.MemberId, INVOKE_PROPERTYGET))
End If
Debug.Print PropertyString
End If
Next
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top