Link to home
Start Free TrialLog in
Avatar of MrDeveloper
MrDeveloper

asked on

is there any way to use refer to one an object's properties using a variable?

Like this:

txtBox.value = GetObjectProperty(myObject, PropertyName)


    Private Function GetObjectProperty(ByVal myObject As Object, ByVal CL As Object, ByVal PropertyNameAs String) As String

Dim strResults as string

strResults = myObject.PropertyName

    Return strResults

End Function
Avatar of newyuppie
newyuppie
Flag of Ecuador image

im not sure i fully understand what you are trying to do... what is your objective? maybe theres different approach...
Avatar of Xeavn
Xeavn

Couldn't you just save yourself a step by doing  txtBox.value = myObject.PropertyName

Depending on the Property you might need to convert in into a string first, but I guess I don't see the reason for trying to call a function to retrieve the property, when you can just ask for the property.
I think the goal here is to retrieve the property by name at run-time.... not programatically.

Every time I've seen the question, the eventual answer has been... not easily. You might be able to do it with reflection, but you take a pretty big performance hit.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
See... I knew as soon as I said it was difficult someone would be along to prove me wrong :)
Avatar of MrDeveloper

ASKER

wow Idle_Mind , that is amazing.  This is really powerful - thank you so much.  Worked perfectly...