Results 1 to 6 of 6

Thread: [RESOLVED] [2005] Need help working with multiple forms :s

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    160

    Resolved [RESOLVED] [2005] Need help working with multiple forms :s

    Hi, can someone help me please.. I have a textbox on frm2 which has a default text value of 5. Now from frmMain I can do frm2.Show() and then change the value to 10 in the textbox. In the frm2_closing event I have Me.Hide() and e.Cancel = True so that frm2 is only hidden and not closed. Now if I close (ie hide) frm2 after changing the value to 10, this is fine, and it will still be 10 if I do frm2.show() again from frmmain. But if I try to access the textbox from frmmain, with frm2.textbox.text, the value will always be 5.. when it should be 10 :S can anyone help me fix this?
    Thanks

  2. #2
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: [2005] Need help working with multiple forms :s

    Look into cross threading... it can cause problems (including errors)... and cross threading is what you are doing I believe...

  3. #3
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2005] Need help working with multiple forms :s

    When creating an instance of Form2, showing it, changing the text value of the textbox, and then hiding it, you must call the same instance to access the text value. If you dispose of that instance, instantiate Form2 again and access the text property, of course it's going to be 5.

    Summary: Use the same instance of Form2 for everything.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    160

    Re: [2005] Need help working with multiple forms :s

    Quote Originally Posted by Fromethius
    When creating an instance of Form2, showing it, changing the text value of the textbox, and then hiding it, you must call the same instance to access the text value. If you dispose of that instance, instantiate Form2 again and access the text property, of course it's going to be 5.

    Summary: Use the same instance of Form2 for everything.
    Ok, but how do I call the same instance again - after I've hidden it?


    Edit:

    I tried this in frmMain
    Dim frm2 As Form2

    and then using frm2.show and accessing frm2.textbox.text
    but when I try to run the program, it immediatly throws an exception saying object reference not set to an instance of the object :s
    Last edited by 4xzer0; Dec 16th, 2007 at 06:26 AM.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Need help working with multiple forms :s

    I'm always very fond of trying to help people whose code isn't working without ever actually seeing the code that isn't working. Doctors and motor mechanics are two other groups that come to mind who would also enjoy similar challenges. In this case though, I think you probably should post the code relevant to the issue.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    160

    Re: [2005] Need help working with multiple forms :s

    well I've got it working now :d

    turned out I needed to use 'New' to get past that exception, so now I have
    Dim frm2 as New Form2 <-- this at the top of my frmMain
    and now I can use frm2.Show() and frm2.Textbox.Text to access the textbox and it's working fine now thanks frometheus

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