Switchboard in VB.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom  T via DotNetMonster.com

    #1

    Switchboard in VB.net

    Hello all.. I'm making a dynamic menu in VB net for an aplication but i'm
    having an issue ...

    I need to use a varable as part of an argument when opening new forms..

    example..

    Dim X as string
    x= rs.fields("form name")

    dim View me as new X

    how do I get VB.Net to reconize that x is an aculy form and create a new
    instance of it...

    Many thanks,

    Tom T

    --
    Message posted via http://www.dotnetmonster.com
  • chuck rudolph

    #2
    RE: Switchboard in VB.net

    Tom, If I understand you, you want to pass an argument to a new form when you
    create the form. So you want code like:

    Dim frm As New Form2(myVariabl e)

    Then in the From2.vb code you need to add a constructor for the variable
    provided. Like the following which changes the title of the new form to the
    string that is passed to it on the creation. (ByVal is the default.)

    Public Sub New(ByVal x)
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeCompo nent()

    'Add any initialization after the InitializeCompo nent() call
    Me.Text = x
    End Sub


    "Tom T via DotNetMonster.c om" wrote:
    [color=blue]
    > Hello all.. I'm making a dynamic menu in VB net for an aplication but i'm
    > having an issue ...
    >
    > I need to use a varable as part of an argument when opening new forms..
    >
    > example..
    >
    > Dim X as string
    > x= rs.fields("form name")
    >
    > dim View me as new X
    >
    > how do I get VB.Net to reconize that x is an aculy form and create a new
    > instance of it...
    >
    > Many thanks,
    >
    > Tom T
    >
    > --
    > Message posted via http://www.dotnetmonster.com
    >[/color]

    Comment

    • Joshua Flanagan

      #3
      Re: Switchboard in VB.net

      My VB.NET is rusty, so hopefully you can figure out the equivalent code.
      This c# code will work:

      string x = rs.fields("form name")
      // note that formname must be the full name of the class
      // including the namespace
      Type formType = Type.GetType(x) ;
      System.Reflecti on.ConstructorI nfo constructor =
      formType.GetCon structor(new Type[0]);

      Form newForm = (Form) constructor.Inv oke(new object[0]);
      newForm.Show();

      The key methods to look at are the static Type.GetType() and instance
      method Type.GetConstru ctor(). They will let you create an instance of
      an class, when you only have the name of the class as a string.


      Joshua Flanagan




      Tom T via DotNetMonster.c om wrote:[color=blue]
      > Hello all.. I'm making a dynamic menu in VB net for an aplication but i'm
      > having an issue ...
      >
      > I need to use a varable as part of an argument when opening new forms..
      >
      > example..
      >
      > Dim X as string
      > x= rs.fields("form name")
      >
      > dim View me as new X
      >
      > how do I get VB.Net to reconize that x is an aculy form and create a new
      > instance of it...
      >
      > Many thanks,
      >
      > Tom T
      >[/color]

      Comment

      Working...