creating a backspace command button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Work007
    New Member
    • Mar 2007
    • 4

    creating a backspace command button

    i am trying to create a button so that when it is clicked it removes the values ina textbox one by one from right to left. i have done this:

    Private Sub Button38_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Button38.Click
    If Len(TextBox1.Te xt) > 0 Then
    TextBox1.Focus( )
    TextBox1.Text = " "
    End If

    But this removes all of the values in the textbox. How can the values be removed one by one each time the button is clicked?
  • yoda
    Contributor
    • Dec 2006
    • 291

    #2
    Originally posted by Work007
    i am trying to create a button so that when it is clicked it removes the values ina textbox one by one from right to left. i have done this:

    Private Sub Button38_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Button38.Click
    If Len(TextBox1.Te xt) > 0 Then
    TextBox1.Focus( )
    TextBox1.Text = " "
    End If

    But this removes all of the values in the textbox. How can the values be removed one by one each time the button is clicked?

    Just a question why would need that when you just hit the backspace on the keyboard and do it that way?

    Comment

    • isotope11
      New Member
      • Mar 2007
      • 10

      #3
      Try this:

      TextBox1.Text = Left(TextBox1.T ext,(Len(TextBo x1.Text)-1))

      Comment

      • devonknows
        New Member
        • Nov 2006
        • 137

        #4
        Originally posted by isotope11
        Try this:

        TextBox1.Text = Left(TextBox1.T ext,(Len(TextBo x1.Text)-1))
        Or there is another way of doing it, less brackets in there, the len does not have to necessarily been in the brackets, it has to work out the value of len - 1 before it can do the function, so for example, i always find that keeping the code simple can help.

        Text1Box1.Text = Left(TextBox1.T ext, Len(TextBox1.Te xt) - 1)

        In the code below ive given you a few extra samples in there to help you, so that it puts it to the end of the line and re-highlights the textbox as you click the button so you dont have to click back on the textbox (lazy i know its a trait i love)

        Code:
        Private Sub Command1_Click() 'Click Button
            'Check to see if length is more than 1 to avoid error or use 'On Error Resume Next'
            If Len(Text1.Text) > 0 Then
                
                'Remove Last Character
                Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
                
                'Set focus back on text box
                Text1.SetFocus
                
                'Set to end of line
                Text1.SelStart = Len(Text1.Text) + 1
            End If
        End Sub
        Well hope this helps.
        Kind Regards
        Devon.

        Comment

        • chaith
          New Member
          • Feb 2014
          • 1

          #5
          Code:
          Private Sub Command1_Click()
          Dim j As Integer
          
          j = Len(Text1.Text)
          If j <> 0 Then
          Text1.Text = Left(Text1.Text, j - 1)
          End If
          End Sub
          Last edited by Rabbit; Feb 20 '14, 04:09 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

          Comment

          Working...