各位大神,看看我的这个VB代码有啥错误 我这是用winsock控件编写一个简单的聊天程序
PrivateSubCommand2_Click()DimIPAsStringIP=InputBox("请输入要连接的IP","输入的IP")Wskclient.Remo...
Private Sub Command2_Click()
Dim IP As String
IP = InputBox("请输入要连接的IP", "输入的IP")
Wskclient.RemoteHost = IP
Wskclient.RemotePort = 1024
Wskclient.Connect
Command2.Enabled = False
End Sub
Private Sub Command1_Click()
Wskclient.SendData Text2.Text '发送数据
Text2.Text = Text2.Text + Chr$(13) + Chr$(10) + "我说:" + Text1.Text '加到聊天记录中
Text1.Text = ""
End Sub
Private Sub wskclient_DataArrival(ByVal bytesTotal As Long)
Dim tempS As String
Wskclient.GetData tempS '接收数据
Text2.Text = Text2.Text + Chr$(13) + Chr$(10) + "对方说:" & tempS '加到聊天记录中
Print
Text2.SelStart = Len(Text2.Text)
End Sub
Private Sub Command3_Click()
Dim i As Integer
i = MsgBox("确定清除聊天记录?", vbOK + vbcancle, "提示您!")
If i <> 1 Then
Text2.Text = Text2.Text
Else
Text2.Text = ""
End If
End Sub
运行时总是这个显示错误
Wskclient.SendData Text2.Text '发送数据
很紧急啊!关系到我过不过科的问题,大神帮忙!!! 展开
Dim IP As String
IP = InputBox("请输入要连接的IP", "输入的IP")
Wskclient.RemoteHost = IP
Wskclient.RemotePort = 1024
Wskclient.Connect
Command2.Enabled = False
End Sub
Private Sub Command1_Click()
Wskclient.SendData Text2.Text '发送数据
Text2.Text = Text2.Text + Chr$(13) + Chr$(10) + "我说:" + Text1.Text '加到聊天记录中
Text1.Text = ""
End Sub
Private Sub wskclient_DataArrival(ByVal bytesTotal As Long)
Dim tempS As String
Wskclient.GetData tempS '接收数据
Text2.Text = Text2.Text + Chr$(13) + Chr$(10) + "对方说:" & tempS '加到聊天记录中
Text2.SelStart = Len(Text2.Text)
End Sub
Private Sub Command3_Click()
Dim i As Integer
i = MsgBox("确定清除聊天记录?", vbOK + vbcancle, "提示您!")
If i <> 1 Then
Text2.Text = Text2.Text
Else
Text2.Text = ""
End If
End Sub
运行时总是这个显示错误
Wskclient.SendData Text2.Text '发送数据
很紧急啊!关系到我过不过科的问题,大神帮忙!!! 展开
3个回答
展开全部
两台电脑必须用两个Winsock控件。我把你的源码改进了一下:
Private Sub cmdConnection_Click()
With wskSend
.RemotePort = 3839
Dim IP As String
IP = InputBox("请输入要连接的IP", "输入的IP")
.RemoteHost = IP
If IP <> "" Then
cmdConnection.Caption = "重新连接"
cmdClean.Enabled = True
cmdSend.Enabled = True
End If
End With
End Sub
Private Sub cmdClean_Click()
Dim i As Integer
i = MsgBox("确定清除聊天记录?", vbYesNo + vbQuestion, "提示您!")
If i = vbYes Then
txtGet.Text = ""
End If
End Sub
Private Sub cmdSend_Click()
wskSend.SendData txtSend.Text
txtGet.Text = txtGet.Text & Chr$(13) & Chr$(10) & "自己说:" & txtSend.Text
End Sub
Private Sub Form_Load()
With wskGet
.Protocol = sckUDPProtocol
.LocalPort = 3839
.Bind 3839
End With
wskSend.Protocol = sckUDPProtocol
cmdClean.Enabled = False
cmdSend.Enabled = False
End Sub
Private Sub wskGet_DataArrival(ByVal bytesTotal As Long)
Dim Text As String
wskGet.GetData Text, vbString
txtGet.Text = txtGet.Text & Chr$(13) & Chr$(10) & "对方说:" & Text
End Sub
Private Sub cmdConnection_Click()
With wskSend
.RemotePort = 3839
Dim IP As String
IP = InputBox("请输入要连接的IP", "输入的IP")
.RemoteHost = IP
If IP <> "" Then
cmdConnection.Caption = "重新连接"
cmdClean.Enabled = True
cmdSend.Enabled = True
End If
End With
End Sub
Private Sub cmdClean_Click()
Dim i As Integer
i = MsgBox("确定清除聊天记录?", vbYesNo + vbQuestion, "提示您!")
If i = vbYes Then
txtGet.Text = ""
End If
End Sub
Private Sub cmdSend_Click()
wskSend.SendData txtSend.Text
txtGet.Text = txtGet.Text & Chr$(13) & Chr$(10) & "自己说:" & txtSend.Text
End Sub
Private Sub Form_Load()
With wskGet
.Protocol = sckUDPProtocol
.LocalPort = 3839
.Bind 3839
End With
wskSend.Protocol = sckUDPProtocol
cmdClean.Enabled = False
cmdSend.Enabled = False
End Sub
Private Sub wskGet_DataArrival(ByVal bytesTotal As Long)
Dim Text As String
wskGet.GetData Text, vbString
txtGet.Text = txtGet.Text & Chr$(13) & Chr$(10) & "对方说:" & Text
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
首先是逻辑错误
Text2.Text = Text2.Text + Chr$(13) + Chr$(10) + "我说:" + Text1.Text '加到聊天记录中
Wskclient.SendData Text2.Text
先扫描你输入的内容然后才能发生,低级错误。
Text2.Text = Text2.Text + Chr$(13) + Chr$(10) + "我说:" + Text1.Text '加到聊天记录中
Wskclient.SendData Text2.Text
先扫描你输入的内容然后才能发生,低级错误。
追问
是Wskclient.SendData Text1.Text这个我忘改了
运行时还有错误,帮忙看看,都看一下,还有啥错误
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询