|
-
Feb 15th, 2010, 07:29 AM
#1
Thread Starter
New Member
[RESOLVED] need help to store data from a closed form
Hi all, I'm creating a small VB programme with several independant forms and I need to transfer data from a textBox in a form already closed to another form. I don't know how . I checked all available books around and searched in MSDN but didn't find answer. Please, provide some help. Thanks
-
Feb 15th, 2010, 07:31 AM
#2
Re: need help to store data from a closed form
Moved From The CodeBank (which is for posting code rather than asking questions)
-
Feb 15th, 2010, 08:45 AM
#3
Re: need help to store data from a closed form
Welcome to the forums... 
I think, when a form is unloaded, you won't be able to access the data inside that Form's textbox or something...
But if you hide that form, then you will be able to access the Textbox of the other form, like this:
where, Form1 is the name of form which contains the Textbox named Text1. ....
And for hiding a form, you can use:
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Feb 15th, 2010, 10:58 AM
#4
Thread Starter
New Member
Re: need help to store data from a closed form
Thanks, man, it worked. I appreciate
-
Feb 15th, 2010, 10:58 AM
#5
Re: need help to store data from a closed form
Stan, when a form is unloaded, any data related to that form is destroyed (public variables may be an exception). So, you want to retrieve that data before the form is unloaded not after.
You have 2 basic choices really & possible combinations between the two. There are other solutions too (i.e., using classes to act as a go-between), but these 2 are the easiest I think.
1. Have that form transfer the data to your main form then unload itself
2. Have your main form open that data form modally, the data form hides itself as suggested above, your main form extracts data then unloads the data form.
Edited: We posted at same time; glad you got it resolved. Be sure to mark this as resolved using the dropdown menu "Thread Tools" near top of your first post.
Last edited by LaVolpe; Feb 15th, 2010 at 11:23 AM.
-
Feb 15th, 2010, 07:48 PM
#6
Re: need help to store data from a closed form
 Originally Posted by LaVolpe
Stan, when a form is unloaded, any data related to that form is destroyed ....
Actually that's not true. Unless you set the form to Nothing, all Public, Private and data such as a texbox's text are retained. Also retained are Private Property values.
-
Feb 15th, 2010, 07:58 PM
#7
Re: need help to store data from a closed form
 Originally Posted by MartinLiss
Actually that's not true. Unless you set the form to Nothing, all Public, Private and data such as a texbox's text are retained. Also retained are Private Property values.
Maybe a misinterpretation on my part. I know that is true for Public values, but not private values...
Any values set during the form's runtime (i.e., user changes the text), that text is lost when the form is unloaded. Simple experiment.
1. In form1, add 2 command buttons
:: Command1: Form2.Show
:: Command2: MsgBox Form2.Text1.Text: Unload Form2
2. In form2, add 1 textbox
:: Text1_Click: Text1.Text = "Hello World": Unload Me
When you show Form2 and click the textbox, the text changes and form unloads. But when you try to query the textbox afterwards, its default value is returned, not "Hello World".
Last edited by LaVolpe; Feb 15th, 2010 at 08:27 PM.
-
Feb 15th, 2010, 08:09 PM
#8
Re: need help to store data from a closed form
Sorry, you're right about textbox's and other controls' values but the rest of what I said is true.
-
Feb 15th, 2010, 08:27 PM
#9
Re: need help to store data from a closed form
 Originally Posted by MartinLiss
Sorry, you're right about textbox's and other controls' values but the rest of what I said is true.
Thanx for the info on the Private values. That is information I wish I would have learned 10+ years ago. So, if I had declared myArray() in the declarations portion of the form and later resized it to say 10000 elements, when the form unloads that array's elements are not cleared and neither is the memory used for it. I now know the answer to that question is not what I expected before I verified your statement (verified!). I think I will take a look at some of my more recent apps for potential zeroizing of private variable declarations, or setting the unloaded form to Nothing.
So in other words. Private/Public variables declared in a form's declaration section are "static" and only when the form is set to Nothing is the memory for those variables released. Gotcha.
Edited: I definitely learned something new today as may many others that read this thread. Thanx.
Last edited by LaVolpe; Feb 15th, 2010 at 08:50 PM.
-
Feb 15th, 2010, 08:52 PM
#10
Re: need help to store data from a closed form
 Originally Posted by LaVolpe
Thanx for the info on the Private values. That is information I wish I would have learned 10+ years ago. So, if I had declared myArray() in the declarations portion of the form and later resized it to say 10000 elements, when the form unloads that array's elements are not cleared and neither is the memory used for it. I now know the answer to that question is not what I expected before I verified your statement (verified!). I think I will take a look at some of my more recent apps for potential zeroizing of private variable declarations, or setting the unloaded form to Nothing.
So in other words. Private/Public variables declared in a form's declaration section are "static" and only when the form is set to Nothing is the memory for those variables released. Gotcha.
Edited: I definitely learned something new today as may many others that read this thread. Thanx.
You're welcome. We learn from each other.
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
|