用ON ERROR
'/////////////////////////////////////////////////////////////////////
'//名称: SendData
'//功能: send command to computer
'//入口: COMMAND, Computer, SendTime
'//出口:
'//返回值:
' 0: failue
' 1: success
'/////////////////////////////////////////////////////////////////////
Public Function SendData(Command As Long, Computer As String, _
SendTime As Date, Optional Flag As Long) As Long
Dim mskSend As HHMsgSock
Dim sDataSend As String
If Flag = 0 Then
mskSend.RoomComputer = Computer
mskSend.SendCommand = Command
mskSend.SendDirection = HH_WATCH
mskSend.SendTime = SendTime
' If Command < 50 Then 'resend data
' If Command <> 5 Then
' frmMain.mRetryTimes = 2
' frmMain.tmrReSend.Enabled = True
' End If
' End If
Else
sDataSend = gstrLastSend
End If
sockClient.RemoteHost = "255.255.255.255"
sockClient.RemotePort = PORTWATCH
On Error GoTo ErrHandle
sockClient.SendData sDataSend
On Error GoTo 0
SendData = 1
Exit Function
ErrHandle:
If Err.Number = 126 Then
Resume Next
Else
MsgBox Err.Number & Err.Description
End If
我知道你的问题,请尝试如下解决方案:
1。请确保在发送前绑定(BIND)端口。
2。这一步是关键。请在发送数据过程开始处使用错误捕获,例如:
Private sub go ()
'ready to send data
On Error Goto LLL
Winsock1.senddata str
exit sub
LLL:
tmpstr=err.description
end sub
这样就不会出现你的问题了。该问题的关键在于即使什么错误也不发生你也必须设置错误捕获,估计这是VB的一个BUG。