|
-
Dec 15th, 2007, 08:43 PM
#1
Thread Starter
Addicted Member
[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
-
Dec 15th, 2007, 08:47 PM
#2
Frenzied Member
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...
-
Dec 15th, 2007, 08:48 PM
#3
Frenzied Member
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.
-
Dec 16th, 2007, 06:20 AM
#4
Thread Starter
Addicted Member
Re: [2005] Need help working with multiple forms :s
 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.
-
Dec 16th, 2007, 06:26 AM
#5
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.
-
Dec 16th, 2007, 06:48 AM
#6
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|