troubleshooting Question

Refer to Form by String (Visual Studio 2008)

Avatar of CIW_George
CIW_GeorgeFlag for United States of America asked on
Visual Basic Classic.NET Programming
19 Comments1 Solution408 ViewsLast Modified:
How do I refer to a form in my project by using a string variable?  I'm running Visual Studio 2008.

My main screen has a number of dropdown menus that, when an item is selected, a form will open:

        Dim Mdi_frm_Doors As New frm_Doors
        Mdi_frm_Doors.MdiParent = Me

In this example, I am providing the name of the form directly (frm_Doors).  What I would like to do is refer to the form as a string variable.

I'm already doing something similar to access specific controls on other open forms (where str_Field is the name of the control I am accessing):

      frm_1.Controls(str_Field).ForeColor = Color.Red

There's got to be something similar for forms.  NOTE:  The form I am trying to open is not already open, so I cannot use a loop like:

        For Each CurrentForm As Form In Application.OpenForms
            If CurrentForm.Name.IndexOf("frm_Cabinet_Assembly_Detail") >= 0 Then

I would prefer not to create an array of all forms in my project, but rather provide the name of a form as a string directly in the code.  I've tried the following code, but I get a System.ArgumentException error for parameter  typeName@0:

        Dim str_Form As String = "frm_Construction_Methods"

        Dim strFormToOpen As String = "[Solid Explorer]." & str_Form

        Dim obhNew As Runtime.Remoting.ObjectHandle
        obhNew = Activator.CreateInstance(Nothing, strFormToOpen)  ' <<<< Error generated here.
        Dim frmNew As Form = DirectCast(obhNew.Unwrap, Form)

I apologize if I have missed something obvious that has already been posted somewhere - I may not be searching for the correct terminology.

Thank you in advance for your help!

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 19 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros