How to get Reference to a Varible by Name (String)
Posted on 2008-06-12
I have a form that has a combobox with the list of variable names available to the user. The user selects the one he needs and with that name, I need to return or show the value in that Variable. Here is an abstract sample of what I need.
Public class Test1
Private mvar1 as String = "Value 1"
Private mvar2 as decimal = 23.54
Private oview as DataView = New Dataview()
Public function GetVarValue(byval VarName as String) as Object
dim ReturnVal as Object = Nothing
' do something here to get the value. This is what I need
' ReturnVal = GetVarRef(VarName).Text
' ReturnVal = GetViewRef(VarName).rows(0)("field1")
From Another Class I want to call that Function and Get the Object Value Like
Dim Obj as Object = Test1.GetVarValue("mvar1")