In .Net each class is a type, so when you create a form it is inherited from base class Form, when you name it for example testForm then this is a class of its own. To create a new instance of a type from its string name you have to use reflection (you can't write: Dim x As New "testForm1"), or a Select Case with one case for each type, for simple cases with just a few cases this is easier. For example you have two forms testForm1 and testForm2, both have the DisplayForm method:
Sub createformCase(ByVal name As String)
Select Case name
Case "testForm1"
Dim f As New testForm1
f.Displayform()
Case "testForm2"
Dim f As New testForm2
f.Displayform()
End Select
End Sub
"As New" is short for "Dim f As testForm1 = New testForm1"; declaring the variable, creating the instance and assigning it to the variable.
For reflection the instance created is returned as type Object, you can use late-binding to call the public method directly from this object, but no intellisense support and it's not safe coding. To access the method from the type you have to cast the object to that type. The above example you could have been written like this:
Dim f As Object = New testForm1
f.DisplayForm() 'late-binding, Object type doesn't have a DisplayForm method, but this works too
DirectCast(f, testForm1).DisplayForm() 'casting and early-binding, testForm1 type have a DisplayForm method
You can't cast to a string literal that is supposed to represent a type. So you couldn't do this:
DirectCast(f, "testForm1").DisplayForm()
Here's where interfaces come to play, you should read up on that topic if it's new to you, it's basic OOP knowledge. In short, all your forms that need to have the DisplayForm method can implement an interface that serves as some kind of base type and provides access to this method, so they can all be casted to the interface type. Here an example of such interface:
Interface IForm
Sub DisplayForm(Optional ByVal input As String = Nothing)
End Interface
And here a form implementing it:
Public Class testForm
Implements IForm
Public Sub DisplayForm(Optional ByVal input As String = Nothing) Implements IForm.DisplayForm
If input IsNot Nothing Then
Me.Text = input 'just sets the input as form title
End If
Me.Show()
End Sub
End Class
and finally on to the reflection variant of the createform method:
Sub createformReflection(ByVal name As String)
Dim f As IForm = Me.GetType.Assembly.CreateInstance(Me.GetType.Namespace & "." & name) 'implicit type casting to IForm
f.DisplayForm("testing") 'IForm type have a DisplayForm method
End Sub