CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2001
    Posts
    42

    Point to a form with a variable

    I would like to be able to call a form and change it settings using a variable, something like


    MyVar = "Form1"
    MyVar.visible = true



    This obviously doesn't work in this way. What can i do to accomplish this.




  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Point to a form with a variable

    You can do this using a form object

    dim objForm as Form
    set objForm = Form1
    objForm.Visible = false




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Aug 2001
    Posts
    42

    Re: Point to a form with a variable

    This doesn't do the trick yet.
    Your code:
    dim objForm as Form
    set objForm = Form1
    objForm.Visible = false



    Here Form1 isn't variable. What I want to do is to call the form with a variable name.

    nm = "Form1"
    set ObjForm = nm
    ObjForm.Visible = true



    When I declare dim nm as Form

    then it doesn't work. So what I need is some declations of a variable to be able to point to a form.



  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Point to a form with a variable

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

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    Aug 2001
    Posts
    42

    Re: Point to a form with a variable

    Thanx, but does this also work for a form which was created during design-time?



  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Point to a form with a variable

    The Iouri solution requires that the form exists (means: it has been created in design time).

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  7. #7
    Join Date
    Aug 2001
    Posts
    42

    Re: Point to a form with a variable

    Don't blame the ignorant for not knowing


  8. #8
    Join Date
    Aug 2001
    Posts
    42

    Re: Point to a form with a variable

    Thanx, works perfectly


  9. #9
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Point to a form with a variable

    We don't...

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  10. #10
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Never...

    I never do. Have a nice day.

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  11. #11
    Join Date
    Aug 2001
    Posts
    42

    Re: Point to a form with a variable

    I've encountered another problem when using your suggestion. When i open de Form this way in runtime, it opens perfectly. But when calling a procedure in this form from another form or module a new window opens, which obviously isn't meant to.
    My code looks like this

    Sub Form1_Load()
    Call OpenForms
    Call EditText()
    End Sub




    Sub EditText()
    Formauto1.Text1.Text = "SomeText"
    End Sub




    Sub OpenForms()
    Dim x as Form, strName as string
    strName = "Formauto1"
    set x = Forms.Add(strName)
    x.Show
    End Sub




    The form FormAuto opens correctly in the procedure OpenForms(). However it opens again when calling procedure EditText().

    Any suggestions.




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