Search code examples
vb.netvbagetproperty

Is There a Getproperty or Equivalent Function?


I would like to know if something like this pseudo code:

myVar = "functionName"
call someObject.(myVar evaluation)

which would then be equivalent to:

call someObject.functionName

is possible in VB. I know this is done in some other languages using a GetProperty method.


Solution

  • You can try the CallByName method to accomplish this. There is also an Eval function in VB/VBA.

    Here's the code for that in VB.Net:

    CallByName(YourClassName, "variableName", CallType.SET, valueToSet)
    

    You can even read property using it's string-name:

    someVariable = CallByName(YourClassName, "variableName", CallType.GET)