我是一个编程初学者,我被困在试图理解我的教授给我的这组代码。下面是表单的完整代码:
Option Explicit
Private Sub cmdSend_Click()
Dim sIPAddress As String
sIPAddress = Trim(txtIPAddress)
If sIPAddress = "" Then Exit Sub
With Winsock1
.RemoteHost = sIPAddress
.RemotePort = "1338"
.SendData txtSendMessage
End With
End Sub
Private Sub Form_Load()
With Winsock1
.Close
.Protocol = sckUDPProtocol
.Bind "1337"
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim msg As String
Winsock1.GetData msg, vbString
txtReceiveMessage = msg & vbCrLf & txtReceiveMessage
End Sub这是我不能理解的代码:
With Winsock1
.RemoteHost = sIPAddress
.RemotePort = "1338"
.SendData txtSendMessage
End With
End Sub
Private Sub Form_Load()
With Winsock1
.Close
.Protocol = sckUDPProtocol
.Bind "1337"
End With
End Sub有人能让我明白吗?在接下来的几十年或二十年里,当我遇到这些代码时,逐字逐句的意思会让我的生活变得更容易。谢谢。
发布于 2017-08-10 18:13:20
当表单加载时,将调用Form_Load()并将Winsock的协议设置为UDP,并侦听(绑定)端口1337上的输入。
表单上有一个按钮(cmdSend)。单击它时,它会发送txtSendMessage文本框的内容。
https://stackoverflow.com/questions/45612867
复制相似问题