vb 编写通讯客户端

来源:百度知道 编辑:UC知道 时间:2024/06/02 08:10:02
我在编写一个简单的聊天程序的时候IP总是固定的。能不能把IP查以自定义呢?也就是不要在程序中固定死。其中代码如下:Private Sub Form1_Load()
SockCl.RemoteHost = ("192.168.1.222")
SockCl.RemotePort = 9999
SockCl.Connect
End Sub

Private Sub Form1_Unload(Cancel As Integer)
SockCl.Close
End Sub
Private Sub SockCl_Close()
SockCl.Close
End Sub
Private Sub SockCl_DataArrival(ByVal bytesTotal As Long)
Dim s As String
SockCl.GetData s
Text1.Text = s
End Sub
Private Sub Command1_Click()
SockCl.SendData Text2.Text
End Sub
希望高手能帮我改一下。能把ip弄成不要在程序里固定死的。可以在外外设置的!
如果我的ip地址不是这个呢?我怎么样替换?难道还要开程序在里面编写呀!不可能的吧!在SockCl.RemoteHost = text1.text
改为这个也行。但是我想要一个变量去替换呀。如我把a=text1.text去替换,我只要SockCl.RemoteHost = a 行不行?有什么好的办法?

改为:
Private Sub Form1_Load()
SockCl.RemoteHost = text1.text
SockCl.RemotePort = 9999
SockCl.Connect
End Sub

其中 text1 为文本框类型的用户控件

您说的是动态IP变静态吧, 去研究一下VB域名解析

Private Sub Form1_Load()

End Sub

Private Sub Form1_Unload(Cancel As Integer)
SockCl.Close
End Sub
Private Sub SockCl_Close()
SockCl.Close
End Sub
Private Sub SockCl_DataArrival(ByVal bytesTotal As Long)
Dim s As String
SockCl.GetData s
Text1.Text = s
End Sub
Private Sub Command1_Click()
SockCl.SendData Text2.Text
End Sub
Private Sub Command2_Click()
SockCl.RemoteHost = Text3.Text
SockCl.RemotePort = 9999
SockCl.Connect
End Sub
Private Sub Command3_Click()
SockCl.Close
End Sub

设置一个文本框,text1.text="192.168.1.222"
SockCl.RemoteHost =text1.text