新手报道,按书教程编的程序报Run-time error '40006'错。
客户端Option Explicit
Private IgnoreText As Boolean
Private Sub cmdClear_Click()
Text2 = ""
With Text1
'Clear the text window and
.Text = ""
'retuen the focus
.SetFocus
End With
End Sub
Private Sub Command1_Click()
On Error GoTo ErrHandler
With sckconnect
.RemoteHost = Trim(TxtServerIP)
.RemotePort = Trim(TxtRemotePort)
If .LocalPort = Empty Then
.LocalPort = Trim(TxtLocalPort)
End If
End With
TxtLocalPort.Locked = True
sckconnect.Connect sckconnect.RemoteHost, sckconnect.RemotePort
StatusBar1.Panels(1).Text = "已连接到""&sckconnect.RemoteHost&"
Text1.SetFocus
Exit Sub
ErrHandler:
MsgBox "与指定服务器连接失败", vbCritical
End Sub
Private Sub Form_Load()
TxtServerIP = sckconnect.LocalIP
TxtLocalPort = 1014
TxtRemotePort = 2014
TxtUserName = "张三"
End Sub
Private Sub sckconnect_DataArrival(ByVal bytesTotal As Long)
Dim cdata As String
sckconnect.GetData cdata, vbString
Text2.SelText = cdata
'StatusBar1.Panels(2).Text="Recieved"&bytesTotal&"bytes"
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Static Last_Line_Feed As Long
Dim New_Line As String
If Trim(Text1) = vbNullString Then
Last_Line_Feed = 0
End If
If KeyAscii = 13 Then
New_Line = Mid(Text1, Last_Line_Feed + 1)
Last_Line_Feed = Text1.SelStart
sckconnect.SendData TxtUserName & ("&sckconnect.LocalIP&") & New_Line
StatusBar1.Panels(2).Text = "sent" & (LenB(New_Line) / 2) & "bytes"
End If
End Sub
服务端
Private Sub Form_Load()
sckserver(0).Bind sckserver(0).LocalPort
sckserver(0).Listen
End Sub
Private Sub Form_Unload(Cancel As Integer)
If sckconnetc.State <> sckClosed Then
sckconnetc.Close
End If
End Sub
Private Sub sckserver_connectrequest(Index As Integer, ByVal requestID As Long)
Dim sip As String
Dim I As Integer
sip = sckserver(0).RemoteHostIP
I = 1
Do While I <= sckserver.Ubound
If sckserver(I).RemoteHostIP = sip Then
sckserver(I).Accept requestID
Exit Sub
End If
I = I + 1
Loop
Load sckserver(I)
sckserver(I).Accept requestID
StatusBar1.Panels(1).Text = requestID & "已连接"
End Sub
Private Sub sckserver_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim sdata As String
sckserver(1).GetData sdata, vbString
Text2.SelText = sdata
For I = 1 To sckserver.Count
If sckserver(I).State <> sckClosed Then
sckserver(I).SendData sdata
End If
Next I
End Sub
错误如图:
[[it] 本帖最后由 mayong123 于 2008-11-2 18:03 编辑 [/it]]