Class test
Dim p1 As String
Dim p2 As String
Sub New(ByVal par1 As String, ByVal par2 As String)
p1 = par1
p2 = par2
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim t As test
Dim myvar As String = "p1"
Dim objFieldInfo As System.Reflection.FieldInfo
t = New test("A", "B")
objFieldInfo = GetType(test).GetField(myvar,
Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)
MsgBox(objFieldInfo.GetValue(t).ToString) ' returns "A"
End Sub
--
Best regards,
Carlos J. Quintero
MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
"rambalep" <wb*****@gmail.com> escribió en el mensaje
news:11**********************@g47g2000cwa.googlegr oups.com...
I need to get a class property value, where property name is contained
in a variable.
example:
class test
dim p1 as string
dim p2 as string
end class
...
sub x
dim t as test
dim myvar as string = "p1"
...
'I need to read a property of object t and the name of property is in
"myvar"
?
How can I do it?
Thanks