You'll need to use reflection:
Imports System.Reflection
Sub ShowForm(str As String)
Dim ty As Type = Type.GetType(str)
Dim frm As Object = Activator.CreateInstance(ty)
DirectCast(frm, Form).ShowDialog()
End Sub
Then call the above method as:
ShowForm("MyApplication.users")
Note that the method Type.GetType requires a fully qualified name including
namespace. Since by default Vb.NET adds the project as the default namespace,
you would need to append it to the form name before passing it as a parameter
to Type.GetType (assuming you are using the default settings only). I would
suggest reading up on the documentation of Type.GetType to make sure you
don't end up with null references.
hope that helps..
Imran.
Hi,
I want to have a sub that takes string as argument and then opens a
form that has that string as a class name.
Say:
Class users
Inherits System.Windows.Forms.Form
'display form content
End Class
Sub functions(str As String)
Dim frm As New str 'this is want I'm trying to accomplish -
obviously
doesn't work this way
frm.ShowDialog()
End Sub
And then call it as Sub("users") If I want to accomplish next:
Dim frm As New users
frm.ShowDialog()
Obviously, what I'm trying to do is much more complicated but if I
would know how to accomplish example above I'd be able to do what I
need.
Thanks,
Vlado
http://www.excelleinc.com