[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 :confused:. I checked all available books around and searched in MSDN but didn't find answer. Please, provide some help. Thanks
Re: need help to store data from a closed form
Moved From The CodeBank (which is for posting code rather than asking questions)
Re: need help to store data from a closed form
Welcome to the forums... :wave:
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. ....:wave:
And for hiding a form, you can use:
Re: need help to store data from a closed form
Thanks, man, it worked. I appreciate
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.
Re: need help to store data from a closed form
Quote:
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.
Re: need help to store data from a closed form
Quote:
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".
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.
Re: need help to store data from a closed form
Quote:
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.
Re: need help to store data from a closed form
Quote:
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.