Robin Carl Daynolo
Robin Carl Daynolo

Reputation: 11

visual basic 6 (vb6) meaning of codes

Im a beginner in coding, and Im stuck trying to understand this set of codes given to me by my professor. Here is the entire code of a form:

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

This is the codes I couldnt understand tho:

    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

can anyone make me understand? a word for word meaning would be nicer to make my life easier when I encounter these codes for the next decades or two. thanks.

Upvotes: 0

Views: 506

Answers (1)

Velocedge
Velocedge

Reputation: 1455

When the form loads, Form_Load() is called and sets the Winsock's protocol to UDP and listens (bind) for input on port 1337.

There is a button (cmdSend) on the form. When it's clicked, it sends the contents of the txtSendMessage textbox.

Upvotes: 1

Related Questions