Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

forms visual basic .net -500

Posted on 2004-04-08
6
Medium Priority
?
243 Views
Last Modified: 2013-12-04
i am writing a program in visual studio .net
i have five forms made (form1,form2,form3,form4,form5)

i want the code to open a given form by name.
for example to give the "form2" in a textbox
and then create an instanse of the form "form2" as x and then open the x  on the program .
thanx

0
Comment
Question by:voulgaris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:Leroyski
ID: 10781936
what language are you using, Visual Basic?

If so, all you need to do is:

formname.show

So, if you want form1 to be opened:

form1.show
0
 
LVL 19

Accepted Solution

by:
Fahad Mukhtar earned 1000 total points
ID: 10782013
Unfortunately there is no direct way to do this in VB.NET you have to perform checks on the contents of the textbox
like this:

'**********************
Select Case TextBox1.Text
            Case "form1"
                Dim frm1 As New Form1()
                frm1.Show()

            Case "form2"
                Dim frm2 As New Form2()
                frm2.Show()

                .........

End Select

'**********************
0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 1000 total points
ID: 10782263
This is result of my test. Create new VB.NET Windows application. Add Button1 and TextBox1 to Form1. Add new Form2 and Form3 to the project. This is Form1 code:

Imports System.Reflection
Imports System.Text
...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a As [Assembly]
        Dim f As Form
        Dim s As StringBuilder

        Try
            a = [Assembly].GetExecutingAssembly()

            s = New StringBuilder
            s.Append(a.GetName().Name)
            s.Append(".")
            s.Append(TextBox1.Text)

            f = CType(a.CreateInstance(s.ToString()), Form)

            If f Is Nothing Then
                MessageBox.Show(Me, "Type not found")
            Else
                f.ShowDialog(Me)
            End If

        Catch ex As Exception
            MessageBox.Show(Me, ex.Message)
        End Try
    End Sub

Type Form2 or Form3 in the textbox and press the button.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10782969
I would vote for reflection. Takes care of all forms, so tomorrow if you add a new form, then you don't need to code another case in the switch construct. Handling exceptions could also be easy.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question