422,904 Members | 1,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,904 IT Pros & Developers. It's quick & easy.

VBN2002 - Programmatically creating a form using a string value as name

P: n/a
I am using VB NET 2002. How can I programmatically create a new windows
form using the value of a string variable as the name of the new form?

Public FrmName As String = "MDIChildFrm1"
Public %FrmName% as new Form

Does not work.
I cannot find any information on this anywhere. Please help! Thank You.

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Michael Creager" <md*******@adelphia.net> schrieb:
I am using VB NET 2002. How can I programmatically create a new windows
form using the value of a string variable as the name of the new form?

Public FrmName As String = "MDIChildFrm1"
Public %FrmName% as new Form


You cannot change a variable's name at runtime.

If the type of the form is variable, take a look at the code below:

\\\
Imports System.Reflection
..
..
..
Dim frm As Form = _
DirectCast( _
Activator.CreateInstance( _
Type.GetType("MyApplication.SampleForm") _
), _
Form _
)
frm.Show()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #2

P: n/a
If you want a new form and name it something then;

dim frm as new Form
Form.Name = "nameofyournewform"

If you want to load an existing form using it's name, then do what Herfried
posted.

"Michael Creager" wrote:
I am using VB NET 2002. How can I programmatically create a new windows
form using the value of a string variable as the name of the new form?

Public FrmName As String = "MDIChildFrm1"
Public %FrmName% as new Form

Does not work.
I cannot find any information on this anywhere. Please help! Thank You.

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.