Wow Kevin, thank you for your detailed post and the time to write that code.
Is performance in a desktop app doing this likely to pose a real world problem then?
[quote=463216:@Kevin Gale]If you aren’t concerned about performance you can do this via Introspection.
I’ve just hacked the following together that should do what you want:
[code]Sub SetPropertyValue(pObject As Object, pPropertyName As String, pValue As Variant)
Dim found As Boolean
Dim typeInfoObj As Introspection.TypeInfo
Dim propertyInfoObjList(-1) As Introspection.PropertyInfo
Dim count, i As Int32
Dim thePropertyInfoObj As Introspection.PropertyInfo
found = False
typeInfoObj = Introspection.GetType(pObject)
propertyInfoObjList = typeInfoObj.GetProperties
count = UBound(propertyInfoObjList)
For i = 0 To count
thePropertyInfoObj = propertyInfoObjList(i)
If thePropertyInfoObj.Name = pPropertyName Then
thePropertyInfoObj.Value(pObject) = pValue
found = True
Exit For
End If
Next
If found = False Then
Raise New KeyNotFoundException
End If
End Sub[/code]
Example:
Set the Title property for a window:
SetPropertyValue(Self, "Title", "Hello")
Edit…
To make this a bit more friendlier, put the method into a module and change the declaration:
Extends pObject As Object, pPropertyName As String, Assigns pValue As Variant
Examples of setting properties on a window:
Self.SetPropertyValue("Title") = "Hello"
Self.SetPropertyValue("Width") = 100
[/quote]