locked
I Found an easy way to communicate in VB6 form and applications Ex. Project1.exe communicate with Project2.exe RRS feed

  • General discussion

  • Goodmorning all ...

    I was trying to find a fast and easy way to make communication thrue VB6 forms or applications

    This is how i try and make the applications ... 2 examples  first with mswinsock and second with Linkmode

    Now for the Server application (project1.exe)

    the code for winsock:

    on form load

    Winsock1.LocalPort = 15000
    Winsock1.Listen

    in a timer with 1000ms interval:

    Dim www
    If Check5.Value = 1 Then
    www = "1"
    Else: If Check5.Value = 0 Then www = "11"
    End If
    Winsock1.SendData www'''sends the data to the host (11)

    on winsock connection :

    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    If Winsock1.State <> sckClosed Then Winsock1.Close
    Winsock1.Accept requestID

    Text1(2).Text = "Board 1 Connected On Address 00FF"

    Label19.Visible = False
    Timer18.Enabled = True
    Check5.Enabled = True
    Check6.Enabled = True
    Check7.Enabled = True
    Check8.Enabled = True
    Check9.Enabled = True
    Check10.Enabled = True
    Check11.Enabled = True
    Check12.Enabled = True
    End Sub

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Winsock1.GetData strmsg
    If strmsg = "1" Then
    'Check5(0).Value = 1
    Else
    'Check5(0).Value = 0
    End If
    End Sub

    Private Sub Winsock1_Close()
    Timer18.Enabled = False
    Check5.Enabled = False
    Check6.Enabled = False
    Check7.Enabled = False
    Check8.Enabled = False
    Check9.Enabled = False
    Check10.Enabled = False
    Check11.Enabled = False
    Check12.Enabled = False
    Text1(2).Text = "Board 1 Is Disconnected"

    Label19.Visible = Not Label19.Visible
    Winsock1.Close
    Winsock1.Listen

    End Sub

     

     

    Now for the Host application (project2.exe)

    Private Sub Timer3_Timer()
    On Error Resume Next
    Winsock1.Connect "127.0.0.1", 15000
    Timer3.Enabled = False
    End Sub

    Private Sub Check1_Click()
    Dim www
    On Error Resume Next
    If Check1.Value = 1 Then
    www = "1"
    Else
    www = "0"
    End If
    Winsock1.SendData www 'Text2.Text
    End Sub

     

     

    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    If Winsock1.State <> sckClosed Then Winsock1.Close
    Winsock1.Accept requestID
    Me.Caption = "Connected to " & Winsock1.RemoteHostIP
    Beep
    End Sub

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Winsock1.GetData strmsg
    Text2.Text = strmsg
    Me.Caption = strmsg
    End Sub

     

     

    Now . For the link mode i write the code below

     

    first create 2  folders putting in each a form

    name folder 1 as serv and the second as clien

    name in clien folder the form1 to aa and in serv folder the form1 to bb

    create in each form aa and bb  a new text       Exp... Text1 in form aa and text1 in form bb

    in the aa form go to text1 properties go to linkitem and put the name of the link text , in this case text1(in the other form bb)

    and in linktopic name the other form(again bb so it wil be project1/bb)

    on form load in the 2 forms(aa and bb) put       Text1.LinkMode = 1

    make the same in all forms (link text with linkmode )

    and compile the application.

    every time you type in aa form's text1 your input will transfer to bb form's text1 in real time

    . today i working also in another way to communicate 2 or more applications using the registry and homemade service i build

    last night .

    hope to  help . i have the code so if u like send me email and i will forward it to u

    Friday, December 16, 2011 9:34 AM