CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Visual Basic

  1. #1
    Join Date
    Apr 2001
    Posts
    11

    Visual Basic

    Is there any way by which i can store the name of a form in a variable and then load the form using this variable.

    Thanks.
    Pathak


  2. #2
    Join Date
    Apr 2001
    Location
    P.J., Malaysia
    Posts
    9

    Re: Visual Basic

    try this:


    Dim fMainForm as frmMain

    set fMainForm = new frmMain
    fMainForm.Load




    Where frmMain is the name of your form.
    you may declare fMainForm as public so that you can access it any where in the project.


  3. #3
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    Re: Visual Basic

    You can use something like that:

    'In Module
    option Explicit
    public strFormName as string

    public Sub LoadPrevious()
    Select Case strFormName
    Case "Form1"
    Form1.Show
    Case "Form2"
    Form2.Show
    Case "Form3"
    Form3.Show
    End Select
    End Sub



    In your forms in the place you want assign a new value to strFormName. Let's say if you do in Form1:

    private Sub Form_Unload(Cancel as Integer)
    strFormName = "Form1"
    End Sub



    then later you can load Form1 from any place of your code by calling LoadPrevious. The scenario might be more complicated, like you can use array to store several values.
    HTH
    Vlad



  4. #4
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Visual Basic


    Dim x as Form, strName as string
    strName = Text1.Text
    set x = Forms.Add(strName)
    x.Show





    John G

  5. #5
    Join Date
    Apr 2001
    Posts
    11

    Re: Visual Basic

    This I have tried, here I know frmmain is the form to be opened but i want "frmmain" to be stored in a variable (bcoz i am retriveing the forms name from a table a table)


  6. #6
    Join Date
    Apr 2001
    Posts
    11

    Re: Visual Basic

    Thanks, this solved my problem


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured