KalluMama
asked on
Transfer data between two forms...
I am just learning VB.net and had a question. If i have two forms and want to transfer some data between the two forms; is using the module the best way to do this?
Is that the recomended way or the only way? thanks
Is that the recomended way or the only way? thanks
ASKER
...but is using modules the recommended practice?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Extending on Idle_Minds solution, if the two forms are independent then have a reference to each form global so you can access them from anywhere in your code.
'Define globally
Public Form1_Pointer as Form1
Public Form2_Pointer as Form2
'Define something like this, sounds like you have this part figured out
Public Sub New()
Form1_Pointer = new Form1
Form2_Pointer = new Form2
Form1_Pointer.Show()
Form2_Pointer.Show()
Application.Run(Form1_Poin ter)
End Sub
You can now access either form from anywhere in the code. Just make sure that the varibles being accessed in each form are public.
Form1_Pointer.lbl1.Text = Form2_Pointer.lbl2.Text
'Alternatively, if Form 2 is embedded in (a child of) Form 1 and you want to send data back up to Form 1 from Form 2 without referencing Form1 as a global pointer, try the following.
'In Form 2
CType(CType(Me.Parent, System.Windows.Forms).Pare nt, Form1).ValueOnForm1 = Value
Hope this helps
'Define globally
Public Form1_Pointer as Form1
Public Form2_Pointer as Form2
'Define something like this, sounds like you have this part figured out
Public Sub New()
Form1_Pointer = new Form1
Form2_Pointer = new Form2
Form1_Pointer.Show()
Form2_Pointer.Show()
Application.Run(Form1_Poin
End Sub
You can now access either form from anywhere in the code. Just make sure that the varibles being accessed in each form are public.
Form1_Pointer.lbl1.Text = Form2_Pointer.lbl2.Text
'Alternatively, if Form 2 is embedded in (a child of) Form 1 and you want to send data back up to Form 1 from Form 2 without referencing Form1 as a global pointer, try the following.
'In Form 2
CType(CType(Me.Parent, System.Windows.Forms).Pare
Hope this helps
Form1.TextBox1.Text = Form2.TextBox2.Text