how to create a form based on string

A

aping

i wanna ask about how to create a form based on a string.
usually we create a form with this command:
-------------------------
dim frm as new frmMyForm
-------------------------

but i want to make something like this which is based on a string:
-------------------------
Dim sClassName as String
Dim frm as Form

sClassName = "frmMyForm"
frm = New sClassName
-------------------------

actually i've seen the answer in
http://www.dotnet247.com/247reference/msgs/38/192409.aspx, but i still
confuse how to use it, coz i'm a newbie in .NET
can someone who posted the answer (CJ Taylor or Herfried K. Wagner)or
someone else explain those function to me? becoz' when i paste the
code to my .NET Code, there is some error.

thanks
 
W

Wantless

why do u need to make a form with a string? just in case there may be
another way to do what u want to do.

this may be a rather crude way but i would say using a streamwriter to
write out to a text file with a .vb extension.
i.e.:

Dim sWrite As IO.StreamWriter = New IO.StreamWriter(New
IO.FileStream("theform.vb", IO.FileMode.Create))
sWrite.Write("the form coding")
sWrite.Close()
 
A

aping ong

i want to create a form based on string becoz' i need to create the form
name ("frmMyForm") which is supplied by database. so i can generate the
creating form based on the data on database.
i don't get it why u ask me to create a text file with a .vb extension.
 
R

Richard

Check out
Assembly.CreateInstance(string)

or some other function in System.Reflection

hth

Richard
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed) (aping) scripsit:
i wanna ask about how to create a form based on a string.
usually we create a form with this command:
-------------------------
dim frm as new frmMyForm
-------------------------

but i want to make something like this which is based on a string:
-------------------------
Dim sClassName as String
Dim frm as Form

sClassName = "frmMyForm"
frm = New sClassName
-------------------------

actually i've seen the answer in
http://www.dotnet247.com/247reference/msgs/38/192409.aspx, but i still
confuse how to use it, coz i'm a newbie in .NET
can someone who posted the answer (CJ Taylor or Herfried K. Wagner)or
someone else explain those function to me? becoz' when i paste the
code to my .NET Code, there is some error.

'Activator.CreateInstance' takes the fully qualified class name as a
string and instantiates the class. What's the problem? Which error
occurs?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top