How to pass data between forms in vb6 ?

ShoNuff asked this question on 12/7/2011. It has been viewed 1577 times, and is currently resolved.

I want to know how can I pass data between forms in vb6?

For example: If I have 2forms that contain 2 text boxes , how can i use a button to transfer what's written in a textbox to the other .

Hope You have Answers.


Answer from dwirch on 12/11/2011

In the button click event on form1, you can write directly to the text box on form2, thus:

form2.text1.text = form1.text1.text

This will take the text string in text1 of form1 and plug it in at text1 on form2.

Or you can use global variables. This comes in handy if you want to close the current form before opening the other form. When your event fires (button click, etc), store your value in the global variable. Then, when the other form opens, or on some other event, you can pick up the value from the variable.

The second option is a bit more flexible too, since that value can now be read from any routine that needs it. The first method is more hard-wired, and can only be used for one thing.


Code Links