4 Replies - 325 Views - Last Post: 21 October 2017 - 12:28 AM Rate Topic: -----

#1 Nigels  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 73
  • Joined: 17-May 13

Show me how to put code in Button

Posted 15 October 2017 - 01:11 PM

Hi, I have been reading up on TCP communication at this link
https://code.msdn.mi...-VBNET-f6c48ca0

https://code.msdn.mi...in%20VB.NET.zip

Anyway In the code given they simply use the "Enter" key on the keyboard to send data.

 Public Sub tbinKD(ByVal sender As Object, _
                       ByVal e As KeyEventArgs) Handles tbin.KeyDown

        If e.KeyCode = Keys.Enter Then

            With CType(sender, TextBox)
                If .Text.Length > 0 Then
                    StatusLabel_send.Image = My.Resources.ledCornerGray
                    myChat.SendData(.Text, tbx_remoteIP.Text, CInt(tbx_remotePort.Text))
                    txtOutSend(.Text)
                    .Text = String.Empty
                End If

            End With
        End If

    End Sub


What I wanted was to put the code in to a button. I was wandering if someone here would show me how.

Is This A Good Question/Topic? 0
  • +

Replies To: Show me how to put code in Button

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13495
  • View blog
  • Posts: 53,911
  • Joined: 12-June 08

Re: Show me how to put code in Button

Posted 15 October 2017 - 03:05 PM

I would say you just use the lines 7-12 and instead of line 06 with the sender you just use a specific textbox variable name.
Was This Post Helpful? 1
  • +
  • -

#3 Nigels  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 73
  • Joined: 17-May 13

Re: Show me how to put code in Button

Posted 16 October 2017 - 09:43 AM

Hi Modi123_1,
You were spot on with that I simply renamed the sender to the name of the TextBox. So my code looked like below with "lbout1" being the name of the TextBox.
 With CType(lbout1, TextBox)
            If .Text.Length > 0 Then
                StatusLabel_send.Image = My.Resources.ledCornerGray
                myChat.SendData(.Text, tbx_remoteIP.Text, CInt(tbx_remotePort.Text))
                txtOutSend(.Text)
                .Text = String.Empty
            End If

        End With


Thanks a million.
Was This Post Helpful? 0
  • +
  • -

#4 IronRazer  Icon User is offline

  • Custom Control Freak
  • member icon

Reputation: 1449
  • View blog
  • Posts: 3,686
  • Joined: 01-February 13

Re: Show me how to put code in Button

Posted 16 October 2017 - 10:26 AM

If lbout1 is the name of your TextBox, then you do not need to cast the lbout1 textbox to a textbox in the With...End With statement, lbout1 is already a textbox. The With statement would be just this....
With lbout1

    ' rest of your code....

End With


Was This Post Helpful? 1
  • +
  • -

#5 Nigels  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 73
  • Joined: 17-May 13

Re: Show me how to put code in Button

Posted 21 October 2017 - 12:28 AM

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1