make a classname a variable

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"
 
A

Andy Gaskell

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
 
F

Frank Eller [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top