我在程序中用一个计时器定期来向各个客户端发送信息来判断客户端是否有掉线代码如下。
Private Sub Timer1_Timer()
On Error Resume Next
For x = 0 To wsArray.UBound
If wsArray(x).State <> 7 Then
wsArray(x).SendData "times"
“如果wsarray(x)是断线的话发送数据times时会出错我们可以在wsarray.error事件中将它关闭。问题是我们要如何抓到这个错误,让程序继续执行,因为可能有多个断线的客户端。
DoEvents
Next x
Timer1.Enabled = False
以上代码执行总是提示少next.
DoEvents前加个End if
On Error goto errline
For x = 0 To wsArray.UBound
If wsArray(x).State <> 7 Then wsArray(x).SendData "times"
Next
Timer1.Enabled = False
exit sub
Errline:
msgbox error
End Sub
改成这样试试,看错在哪了。