I have an application that I would like to use strings from the textboxes to open forms, by storing the form name in the textbox on open or close.

Dim strName as string
Dim frm as Form
If strName = String.Empty then
strName = frmMain
Else
strName = frmMain.txtFormOpen.txt
frm = strName
End If

but I get an error that a string is not or can not be converted to a form :(

Any help would be greatly appreciated. Thank you in advance

Michael

confusing...
open form or assign name to formName?
is this code for vb 6?

The application is in VB.NET 2005.

I would like to be able to create code to open the form based on the text in the textbox.

Assign name and open the form with code.

Michael

To open a form, you need to create an instance of the form object.

Ok, thank you, but how do I do that in code please?

The application is in VB.NET 2005.

I would like to be able to create code to open the form based on the text in the textbox.

Assign name and open the form with code.

I have an application that I would like to use strings from the textboxes to open forms, by storing the form name in the textbox on open or close.

Dim strName as string
Dim frm as Form
If strName = String.Empty then
strName = frmMain
Else
strName = frmMain.txtFormOpen.txt
frm = strName
End If

but I get an error that a string is not or can not be converted to a form

Any help would be greatly appreciated. Thank you in advance

Ok, thank you, but how do I do that in code please?

Dim myForm As New Form1
myForm.ShowDialog()

you have confusing program.
iaeDave already answer the question.

Dim myForm As New Form1
myForm.ShowDialog()

that code used to call other form

I think the only way you can do it is via a select case statement and hard code your form names in there, i.e.

Select Case strName
  Case "frm1"
    dim frm as new frm1
  Case "frm1"
    dim frm as new frm2
end select
frm.showdialog()

This is not as restricting as it seems as you will have a finite number of forms at design time, you only need to remember to add them in to the select statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.