Hi everyone,
I was wondering if anyone can help me. I got two forms I can send data from one form to the other one when I press the SEND button. I’m trying to get data from one form to the other when I press the ‘GET’ button, to get an idea what I’m trying to do have a look at this image:

http://i389.photobucket.com/albums/oo336/neovo-88/VB.jpg

Hopefully it will make it more clear what I’m trying to do. Also before anything is done you have to press the ‘CONNECT’ button, to link to the forms first.

Here the code I used so far:

Form1

Private Sub Form_Load()
tcpServer.LocalPort = 1001
tcpServer.Listen
frmClient.Show
End Sub
Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)
If tcpServer.State <> sckClosed Then tcpServer.Close
tcpServer.Accept requestID
End Sub
'Listens for data from form 1 and displays it
Private Sub tcpServer_DataArrival(ByVal bytestotal As Long)
Dim strData As String
tcpServer.GetData strData
txtInput.Text = strData
End Sub
Private Sub timer1_timer()
Label1.Caption = tcpServer.State
If tcpServer.State = 0 Then tcpServer.Listen
End Sub

Form 2

Private Sub Form_Load()
tcpClient.RemoteHost = "localhost"
tcpClient.RemotePort = 1001
End Sub
'Connect Form 2 to Form 1
Private Sub cmdConnect_Click()
tcpClient.Connect
End Sub
'Sends data from form 1 to Form 1
Private Sub Command1_Click()
tcpClient.SendData txtOutput.Text
End Sub
Private Sub timer1_timer()
Label1.Caption = tcpClient.State
End Sub

Any help will much appreciated

Thanks

Rich

'In Form2

Option Explicit

Private Sub Form_Load()

    On Error GoTo Form_Load_Error

    tcpClient.RemoteHost = "localhost"
    tcpClient.RemotePort = 1001

Form_Load_Done:
    Exit Sub

Form_Load_Error:
    MsgBox Err.Number & " : " & Err.Description
    Resume Form_Load_Done

End Sub

'Connect Form 2 to Form 1
Private Sub cmdConnect_Click()

    On Error GoTo cmdConnect_Click_Error

    If tcpClient.State <> sckClosed Then tcpClient.Close
    tcpClient.Protocol = sckTCPProtocol
    tcpClient.Connect

cmdConnect_Click_Done:
    Exit Sub

cmdConnect_Click_Error:
    MsgBox Err.Number & " : " & Err.Description
    Resume cmdConnect_Click_Done

End Sub

'Sends data from form 1 to Form 1
Private Sub Command1_Click()

    On Error GoTo Command1_Click_Error

    tcpClient.SendData txtOutput.Text

Command1_Click_Done:
    Exit Sub

Command1_Click_Error:
    MsgBox Err.Number & " : " & Err.Description
    Resume Command1_Click_Done

End Sub

Private Sub timer1_timer()

    On Error GoTo timer1_timer_Error

    Label1.Caption = tcpClient.State

timer1_timer_Done:
    Exit Sub

timer1_timer_Error:
    MsgBox Err.Number & " : " & Err.Description
    Resume timer1_timer_Done

End Sub

Private Sub Command2_Click()

    On Error GoTo Command2_Click_Error

    tcpClient.SendData "SETDATA"

Command2_Click_Done:
    Exit Sub

Command2_Click_Error:
    MsgBox Err.Number & " : " & Err.Description
    Resume Command2_Click_Done

End Sub

'Listens for data from form 1 and displays it
Private Sub tcpClient_DataArrival(ByVal bytestotal As Long)

    Dim strData As String

    On Error GoTo tcpClient_DataArrival_Error

    tcpClient.GetData strData
    txtInput.Text = strData

tcpClient_DataArrival_Done:
    Exit Sub

tcpClient_DataArrival_Error:
    MsgBox Err.Number & " : " & Err.Description
    Resume tcpClient_DataArrival_Done

End Sub

'In Form1

Option Explicit

Private Sub Form_Load()

    On Error GoTo Form_Load_Error

    tcpServer.LocalPort = 1001
    tcpServer.Listen
'    frmClient.Show

Form_Load_Done:
    Exit Sub

Form_Load_Error:
    MsgBox Err.Number & " : " & Err.Description
    Resume Form_Load_Done

End Sub

Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)

    On Error GoTo tcpServer_ConnectionRequest_Error

    If tcpServer.State <> sckClosed Then tcpServer.Close
    tcpServer.Accept requestID

tcpServer_ConnectionRequest_Done:
    Exit Sub

tcpServer_ConnectionRequest_Error:
    MsgBox Err.Number & " : " & Err.Description
    Resume tcpServer_ConnectionRequest_Done

End Sub

'Listens for data from form 1 and displays it
Private Sub tcpServer_DataArrival(ByVal bytestotal As Long)

    Dim strData As String

    On Error GoTo tcpServer_DataArrival_Error

    tcpServer.GetData strData
    If InStr(1, strData, "SETDATA") > 0 Then
        tcpServer.SendData txtOutput.Text
    Else
        txtInput.Text = strData
    End If

tcpServer_DataArrival_Done:
    Exit Sub

tcpServer_DataArrival_Error:
    MsgBox Err.Number & " : " & Err.Description
    Resume tcpServer_DataArrival_Done

End Sub

Private Sub timer1_timer()

    On Error GoTo timer1_timer_Error

    Label1.Caption = tcpServer.State
    If tcpServer.State = 0 Then tcpServer.Listen

timer1_timer_Done:
    Exit Sub

timer1_timer_Error:
    MsgBox Err.Number & " : " & Err.Description
    Resume timer1_timer_Done

End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.