Click to See Complete Forum and Search --> : Passing data between forms...


YourSurrogateGod
July 25th, 2005, 03:41 PM
Ok, I have 2 forms. Form1 creates Form2. My question is, how can I pass information between the two of them? For example, if I had a DB connection object that needed to be passed from one to the other, how can I pass that object? Or any other object for that matter...
Public Class Form1
Inherits System.Windows.Forms.Form
Dim new_form As New Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
new_form.Show()
End Sub
End Class
Public Class Form2
Inherits System.Windows.Forms.Form
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load

End Sub
End Class

venAdder
July 25th, 2005, 05:02 PM
What I did to share data between forms is have a module and declare the variables int eh module as friend. Youc an read and wrtie tot his variable
e.g.

Option Explicit On
Option Strict On
Module GlobalData
Friend g_CReg As New CReg
End Module

now this variable g_Creg is accesible throughouyt the app.

Mayeb this will solve your problem.

YourSurrogateGod
July 25th, 2005, 07:07 PM
What I did to share data between forms is have a module and declare the variables int eh module as friend. Youc an read and wrtie tot his variable
e.g.

Option Explicit On
Option Strict On
Module GlobalData
Friend g_CReg As New CReg
End Module

now this variable g_Creg is accesible throughouyt the app.

Mayeb this will solve your problem.
That actually went quite a bit in the way to solving my problem.

By doing the below, will I get a thread-safe module?
<System.Runtime.Remoting.Contexts.Synchronization()> Module pass_around
Public int As Integer = 0
End Module