Results 1 to 10 of 10

Thread: [RESOLVED] need help to store data from a closed form

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Location
    Bulgaria
    Posts
    2

    Resolved [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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: need help to store data from a closed form

    Moved From The CodeBank (which is for posting code rather than asking questions)

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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:
    Code:
    Form1.Text1.Text
    where, Form1 is the name of form which contains the Textbox named Text1. ....

    And for hiding a form, you can use:
    Code:
    Form1.hide

    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,...

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Location
    Bulgaria
    Posts
    2

    Thumbs up Re: need help to store data from a closed form

    Thanks, man, it worked. I appreciate

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: need help to store data from a closed form

    Quote Originally Posted by LaVolpe View Post
    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.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: need help to store data from a closed form

    Quote Originally Posted by MartinLiss View Post
    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: need help to store data from a closed form

    Quote Originally Posted by MartinLiss View Post
    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: need help to store data from a closed form

    Quote Originally Posted by LaVolpe View Post
    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
  •  



Click Here to Expand Forum to Full Width