make a classname a variable

  • Thread starter Thread starter Stephen Travis
  • Start date Start date
S

Stephen Travis

Since there is no eval function in VB, is there a way to make a classname a variable? For example;

Dim MyClassInstance1 As New MyClass

Dim somestring as System.String = "MyClassInstance1"
"somestring".someproperty = "somevalue"


....which would set MyClassInstance1.someproperty to "somevalue"
 
MyClassInstance1.GetType().Name

Or if you want to make a property:

Public ReadOnly Property ClassName() As String
Get
ClassName = Me.GetType().Name
End Get
End Property
 
Hi Stephen,
Since there is no eval function in VB, is there a way to make a
classname a variable? For example;

Dim MyClassInstance1 As New MyClass

Dim somestring as System.String = "MyClassInstance1"
"somestring".someproperty = "somevalue"

Doesn't work that way. You should use Reflection instead, look at the
classes in the System.Reflection Namespace. It's a bit too complex to be
explained here ...

Regards,

Frank Eller
www.frankeller.de
 
Back
Top