# 关于vb6, winsock ,error event 的问题

Posted by Shelly on November 02, 1998 at 09:21:38:

设我以Set sktTCPChatClient = CreateObject("MSWinsock.Winsock")建立起
winsock物件,
请问要如何读到此事件的error event呢?

使用vb6.0 企业版 于Win95 下开发, 之前欲移至WinNT 4.0 SP3 上运作.

因为想把以winsock运作的程式码包装起成为activeX component.
所以我的部份程式码如下:
我要如何读取到此事件的error event呢?
我尝试着在定义sktTCPChatClient 这个变数时加上 withEvent ,
同时也在程式的windows的pull-down menu中找到其event.
但是好像用法不对, 程式变得无法正常地建立起winsock object
想请问有谁使用会, 可以教我正确的用法吗?谢谢.
Public Function ConnectTerminalServer()
On Error GoTo ErrorHandler
Dim sktTCPClient As Object

Set sktTCPClient = CreateObject("MSWinsock.Winsock")

If sktTCPClient.State <> sckClosed Then
sktTCPClient.Close
End If

With sktTCPClient
.RemoteHost = sktTCPClient.LocalIP
.RemotePort = 5001
End With

sktTCPClient.Connect '要求连接

Do
If sktTCPClient.State = sckError Then '连接失败
Exit Function
End If
DoEvents '释放控制权
Loop Until sktTCPClient.State = sckConnected '等待连接成功

sktTCPClient.SendData "xxxxxxxxxxxxxxxxxx"

Do
DoEvents '释放控制权
Loop Until sktTCPClient.BytesReceived <> 0 '等待结果

sktTCPClient.GetData strOutbound, vbString '读取结束

sktTCPClient.Close '关闭连线
Set sktTCPClient = Nothing
Exit Function

ErrorHandler:
Set sktTCPClient = Nothing
End Function

Follow Ups:

- Re: 关于vb6, winsock ,error event 的问题 Maxwell 11:21:46 11/02/98 (2)
  - Re: 关于vb6, winsock ,error event 的问题 Shelly 17:53:11 11/03/98 (1)
    - Re: 关于vb6, winsock ,error event 的问题 阿庆 20:33:33 11/03/98 (0)