Convert String To dot Net Form Load Code

  • Thread starter Thread starter Aaron_nesbitt
  • Start date Start date
A

Aaron_nesbitt

Hi,

Is there any way to convert a sting (Pulled from a data tabel) into
VB.NET code?
The original case statment looked like this:

Select Case e.Link.ItemName
Case "frmNEWFORM"
Dim f As frmNEWFORM
f = New frmNEWFORM
f.init()

I would ideally like to have the "frmNEWFORM" held in a database so I
can maintain my menu system from the database.

Is This Possible?

Sub OpenForm(ByVal e As String) 'e is the name of the link being
clicked

For Each ComMenu.ROW In ComMenu.TABLE.Rows
If e = ComMenu.FIELDS.sysdesc.ToString Then

...
...
...

End If
Next
 
Hi,

As I understand, you are trying to instantiate a class by its name and
calling its methods/properties. You could do that with the
System.Reflection namespace.

The first thing to note is that you should store the fully-qualified
class name (that is, including its namespace). If the class is in an
unloaded DLL, you should store the DLL name as well. See
http://msdn2.microsoft.com/en-us/library/w3f99sx1.aspx for the format
of the string.

Then you can use Activator.CreateInstance to create an instance. You
can invoke its methods/properties (like Init method) by calling
Type.InvokeMember. Or better, you should make all your forms inherit a
single class then you could cast the instance to an object of that
class and call its method.

InitializableForm f = (InitializableForm)
Activator.CreateInstance(...).Unwrap();
f.Init();

Hope that helps,
Thi
http://thith.blogspot.com
 
Back
Top