?
Solved

Change string to form

Posted on 2009-05-18
5
Medium Priority
?
332 Views
Last Modified: 2013-11-25
Hi there, i want to change a string to a form name, for example:

dim FormName as string = Form2

dim newform as form = FormName

newform.show()


From what I've read I need to use system.reflection for this but I'm stabbing wildly in the dark.

Thanks!
0
Comment
Question by:garethh86
[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
5 Comments
 
LVL 1

Expert Comment

by:Modar_Hijazi
ID: 24411323
Try the following:
        Dim FormName As String = "My Form"
        Dim newform As Form = New Form
        newform.Name = FormName
        newform.Show()

Open in new window

0
 
LVL 27

Expert Comment

by:Shaun Kline
ID: 24411364
You should be able to create a new form and give the form a name.

Dim FormName as String = Form2
Dim newform as new Form()
newForm.Name = FormName

newForm.Show
0
 
LVL 7

Author Comment

by:garethh86
ID: 24411444
Sorry, that just creates a brand new form, I already have the form created. Im trying to open this form and add to a panel from a treeview based on its tag name.
0
 
LVL 1

Assisted Solution

by:Modar_Hijazi
Modar_Hijazi earned 400 total points
ID: 24411533
Your code must be changed to:

        Dim FormName As String = "Form2"
        Dim newform As Form = New Form
        newform = GetFormByName(FormName)
        newform.Show()

and the method GetFormByName is attached ;)
    Private Function GetFormByName(ByVal formName As String) As Object
 
        Dim myasm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
 
        Try
            Return myasm.CreateInstance(myasm.GetName.Name.Replace(" ", "_") & "." & formName)
 
        Catch ex As Exception
            Return Nothing
        End Try
 
    End Function

Open in new window

0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 1600 total points
ID: 24411536
You are correct - reflection is required. The below example shows how.

Wayne
        Dim FormName As String = "Form2"
        Dim newform As Form = CType(Reflection.[Assembly].GetEntryAssembly.CreateInstance( _
                                    My.Application.Info.AssemblyName & "." & FormName), Form) 
        newform.Show()

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

719 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