Results 1 to 7 of 7

Thread: accessing vars from different form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70

    Resolved accessing vars from different form

    Hi guys, going crazy with this:

    When I want to open a new form I do something like:

    Dim newform as fromclass1 = new formclass1
    newform.show()

    if I want to change a textbox in newform I can do:

    newform.textbox.text= "nice"

    Now, what if I want to access a public element (such as a combobox or textbox) in the original form (from where newform opened) from the form newform?

    I just want to do the same I did above to access newform.textbox but inverse. The form from where newform was called already exists (obviously) and it was called firstform, but doing, from newform:

    firstform.textbox doesn't work,
    not even if I declare firstform as public.

    Hope I explained it clearly enough.

    Thanks
    Last edited by nacho2; Jan 4th, 2005 at 08:48 AM.

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: accessing vars from different form

    Quote Originally Posted by nacho2
    firstform.textbox doesn't work,
    not even if I declare firstform as public.
    How did you declared it public?

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70

    Re: accessing vars from different form

    In the form where firstform opens from instead of writing:

    Dim firstform as formclass2 = new formclass2

    I did:

    Public firstform... same thing

    The most difficult thing about this problem I think it is explaining it!

  4. #4
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: accessing vars from different form

    Declare it has
    Code:
    Public firstform as new firstform
    On firstform load event put this
    Code:
    firstform = me
    on firstform closing event put this
    Code:
    firstform = nothing

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70

    Re: accessing vars from different form

    Don't quiet get it!


    I got a form which opens when I execute the application, lets call it firstfirstform, and it has the following code:

    Public firstform as formclass2 = new formclass2

    later on...

    event click:

    firstform.show()

    Now in firstform got almost the same:

    Public newform as formclass1 = new formclass1

    later on...

    newform.show()

    Now from newform I need to access a textbox which is in firstform, I try to do firstform.textbox.text=...

    but i says I haven't declared firstform.

    I've tried to use the lines you told me but don't seem to work.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70

    Re: accessing vars from different form

    Can I handle an event of newform from firstform?

    instead of this:

    VB Code:
    1. Private Sub firstform_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.closed

    writing something like this:
    VB Code:
    1. Private Sub newform_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles newform.closed

    That above doesn't work but maybe the idea is good.

    Don't know I'm stuck.

    Which event triggers when you go back to a window which never closed but had a new window opened on top? That could help too, I tried gotFocus and Activated and gotFocus doesn't seem to work and activated only triggers the first time you open the window.

    thanks for your help

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70

    Re: accessing vars from different form

    ok got it, i used vars and functions as public shared and that 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