none
Length TEXTBOX COUNT RRS feed

  • Question

  • HI

    I want the number of characters not for each textBOX but The number of characters before the POINT OF cursor

    IMAGE SHOW LENGHT3 NUMBER  NOT 6 NUMBER



    Friday, September 14, 2018 5:25 AM

Answers

  • Hi,

    Is this the effect?

    TEXT_INPUT.Text = TEXT_INPUT.Text.Insert(TEXT_INPUT.SelectionStart, BT_NUM9.Text)

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ahmeddc Friday, September 14, 2018 6:05 PM
    Friday, September 14, 2018 11:25 AM
  • You cannot vote on your own post

    Hi

    I suspect that you haven't thought this through properly. You say you want to insert at the caret position when you press key 9  provide it isn't at the start or end of the text in the textbox.

    If I have understood that correctly, then what do tou want to do with the entered number 9 when the caret is at the start or end of the text in textbox1? Just throw it away? In which case, if you do want to enter a 9 in the textbox, it will never be entered!

    Here is some code that does exactly as you asked (as far as I understand it). When you press 9, then the text in textbox BT_NUM9 will be inserted into TextBox1 at caret,or discarded if caret is at start or end. I really don't think this is something you really want. This is a stand alone example - try it out. Needs 2 Textboxes (TextBox1 and TextBox BT_NUM9)

    ' Form1 with TextBox1,
    ' TextBox BT_NUM9
    Option Strict On
    Option Explicit On
    Public Class Form1
      Sub AddBT_NUM9()
        Dim hss As Integer = TextBox1.SelectionStart
        If hss = 0 Or hss > TextBox1.Text.Length - 1 Then Exit Sub
        TextBox1.Text = TextBox1.Text.Insert(TextBox1.SelectionStart, BT_NUM9.Text)
        TextBox1.SelectionStart = hss + BT_NUM9.Text.Length
        TextBox1.SelectionLength = 0
      End Sub
      Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.D9 Then
          e.SuppressKeyPress = True
          AddBT_NUM9()
        End If
      End Sub
    End Class

    Regards Les, Livingston, Scotland

    • Marked as answer by ahmeddc Friday, September 14, 2018 6:06 PM
    Friday, September 14, 2018 11:52 AM

All replies

  • Hi,

    TextBox1.SelectionStart

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 14, 2018 5:43 AM
  • Hi,

    TextBox1.SelectionStart

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    HI

    EVERY THING WAS GOOD

    I want to add a number or letter to the area I am standing on when I press button 9
    Provided that the index is not at the first point or after the last point

    CODE NOT WORK

      Dim PSITION As Integer = TEXT_INPUT.SelectionStart
            If PSITION > 0 AndAlso PSITION < TEXT_INPUT.SelectedText.Length - 1 Then
                Dim strA As String = ""
                For i = 0 To TEXT_INPUT.SelectionStart
                    strA += BT_NUM9.Text
                Next
                TEXT_INPUT.SelectedText = strA
            End If

    • Edited by ahmeddc Friday, September 14, 2018 5:59 AM
    Friday, September 14, 2018 5:58 AM
  • Hi,

    I don't understand the meaning of your code.

    I try to modify your code:

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim strA As String = ""
            For i = 0 To TEXT_INPUT.SelectionStart + TEXT_INPUT.SelectedText.Length - 1
                strA += BT_NUM9.Text
            Next
            TEXT_INPUT.SelectedText = strA
    
        End Sub
    End Class

    effect:

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, September 14, 2018 7:20 AM
  • Hi,

    I don't understand the meaning of your code.

    I try to modify your code:

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim strA As String = ""
            For i = 0 To TEXT_INPUT.SelectionStart + TEXT_INPUT.SelectedText.Length - 1
                strA += BT_NUM9.Text
            Next
            TEXT_INPUT.SelectedText = strA
    
        End Sub
    End Class

    effect:

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    HI

    I WANT ADD THE NUMBER IN POSITION OF CRUSER

    Friday, September 14, 2018 9:58 AM
  • STOP USING ALL CAPS IN YOUR POSTS!

    Regards Les, Livingston, Scotland


    • Edited by leshay Friday, September 14, 2018 11:23 AM
    Friday, September 14, 2018 11:22 AM
  • Hi,

    Is this the effect?

    TEXT_INPUT.Text = TEXT_INPUT.Text.Insert(TEXT_INPUT.SelectionStart, BT_NUM9.Text)

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ahmeddc Friday, September 14, 2018 6:05 PM
    Friday, September 14, 2018 11:25 AM
  • You cannot vote on your own post

    Hi

    I suspect that you haven't thought this through properly. You say you want to insert at the caret position when you press key 9  provide it isn't at the start or end of the text in the textbox.

    If I have understood that correctly, then what do tou want to do with the entered number 9 when the caret is at the start or end of the text in textbox1? Just throw it away? In which case, if you do want to enter a 9 in the textbox, it will never be entered!

    Here is some code that does exactly as you asked (as far as I understand it). When you press 9, then the text in textbox BT_NUM9 will be inserted into TextBox1 at caret,or discarded if caret is at start or end. I really don't think this is something you really want. This is a stand alone example - try it out. Needs 2 Textboxes (TextBox1 and TextBox BT_NUM9)

    ' Form1 with TextBox1,
    ' TextBox BT_NUM9
    Option Strict On
    Option Explicit On
    Public Class Form1
      Sub AddBT_NUM9()
        Dim hss As Integer = TextBox1.SelectionStart
        If hss = 0 Or hss > TextBox1.Text.Length - 1 Then Exit Sub
        TextBox1.Text = TextBox1.Text.Insert(TextBox1.SelectionStart, BT_NUM9.Text)
        TextBox1.SelectionStart = hss + BT_NUM9.Text.Length
        TextBox1.SelectionLength = 0
      End Sub
      Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.D9 Then
          e.SuppressKeyPress = True
          AddBT_NUM9()
        End If
      End Sub
    End Class

    Regards Les, Livingston, Scotland

    • Marked as answer by ahmeddc Friday, September 14, 2018 6:06 PM
    Friday, September 14, 2018 11:52 AM