' FILE: SerialDAQClinet
' DATE: 05/25/03
' AUTH: C.Hu
Dim flag As Integer
Dim init As Integer
Dim mWord As Word.Application
Private Sub cmdOne_Click()
flag = 1 - flag
' Send one to server
If flag = 1 Then
cmdOne.Caption = "Stop"
' Set up local port and wait for connection
tcpClient.RemoteHost = Text1.Text
If tcpClient.RemoteHost = "" Then
tcpClient.RemoteHost = "localhost"
End If
tcpClient.RemotePort = 5010 ' server port
Call tcpClient.Connect ' connect to RemoteHost address
init = 1
Else
cmdOne.Caption = "Connect"
Call tcpClient.Close
init = 0
End If
End Sub
Private Sub cmdSave_Click()
cmdSave.Enabled = False
Call mWord.Documents.Add
mWord.Selection.Font.Size = 10
Call mWord.Selection.TypeText(txtOutput.Text)
Call mWord.Documents(1).SaveAs("C:\serial.doc")
Call mWord.Quit
End Sub
Private Sub cmdTwo_Click()
If init = 1 Then
Call tcpClient.Close
End If
End
End Sub
Private Sub Form_Load()
flag = 0
init = 0
Set mWord = New Word.Application
End Sub
Private Sub Form_Terminate()
If init = 1 Then
Call tcpClient.Close
End If
End
End Sub
Private Sub tcpClient_Close()
Call tcpClient.Close ' server closed, client should
too
txtOutput.Text = txtOutput.Text & "Server closed connection."
& vbCrLf
txtOutput.SelStart = Len(txtOutput.Text)
End Sub
Private Sub tcpClient_Connect()
' When connection occurs, display a message
txtOutput.Text = "Connected to IP address: " & _
tcpClient.RemoteHostIP & vbCrLf & "Port #: " & _
tcpClient.RemotePort & vbCrLf & vbCrLf
End Sub
Private Sub tcpClient_DataArrival(ByVal
bytesTotal As Long)
Dim message As String
Call tcpClient.GetData(message) ' get data from
server
txtOutput.Text = txtOutput.Text & message
txtOutput.SelStart = Len(txtOutput.Text)
End Sub
Private Sub tcpClient_Error(ByVal
Number As Integer, Description As String, ByVal Scode As Long, ByVal Source
As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay
As Boolean)
' If the client fails to connect to server, then
this code executes
Dim result As Integer
result = MsgBox(Source & ": " & Description & vbCrLf
& "Doh! Can't connect to server!", _
vbOKOnly, "TCP/IP Error")
' Source variable is the control (winsock in this
case) causing the error
' Description variable cites the error message
' vbOKOnly is the control button
' TCP/IP Error is the MsgBox caption
End
End Sub
Private Sub Timer1_Timer()
If flag = 1 Then
If init = 1 Then
Call tcpClient.SendData("1")
End If
End If
End Sub
Private Sub Class_Terminate()
Set mWord = Nothing
End Sub
|