CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Location
    In the back seat of New Horizons.
    Posts
    1,238

    Passing data between forms...

    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...
    Code:
    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
    Code:
    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
    Here are the rules, you must obey them or the gender bender will get you.

    And if you ever think of posting without code-tags, the evil monkey will come after you.

  2. #2
    Join Date
    Aug 2004
    Posts
    391

    Re: Passing data between forms...

    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.

  3. #3
    Join Date
    Apr 2004
    Location
    In the back seat of New Horizons.
    Posts
    1,238

    Re: Passing data between forms...

    Quote Originally Posted by venAdder
    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?
    Code:
    <System.Runtime.Remoting.Contexts.Synchronization()> Module pass_around
      Public int As Integer = 0
    End Module

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

Featured