class from variable

cssslt

New member
Joined
Jul 17, 2009
Messages
3
Programming Experience
Beginner
How can I call a class from a variable ?

Something like :

Dim strClassName As string = "clsAction"
Dim newclass = strClassName

I know that this code doesn't work, but how can I do it, if possible.

Thanks
Martin
 
I have found my answer

VB.NET:
Dim strClassName As String = "clsAction"

Dim classType As Type = Type.GetType("CallCenter." & strClassName)
Dim classObj As Object = Activator.CreateInstance(classType)


Now, I do I call my sub (from a variable) from this class ?

VB.NET:
Dim strSubName = "subAction"

classObj.strSubName ???
 
VB.NET:
Dim method = classType.GetMethod("subAction")
method.Invoke(classObj, Nothing)
 
Back
Top