By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,097 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,097 IT Pros & Developers. It's quick & easy.

creating a backspace command button

P: 4
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.EventArgs) Handles Button38.Click
If Len(TextBox1.Text) > 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?
Mar 20 '07 #1
Share this Question
Share on Google+
4 Replies


yoda
100+
P: 291
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.EventArgs) Handles Button38.Click
If Len(TextBox1.Text) > 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?
Mar 21 '07 #2

isotope11
P: 10
Try this:

TextBox1.Text = Left(TextBox1.Text,(Len(TextBox1.Text)-1))
Mar 21 '07 #3

devonknows
100+
P: 137
Try this:

TextBox1.Text = Left(TextBox1.Text,(Len(TextBox1.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.Text, Len(TextBox1.Text) - 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)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click() 'Click Button
  2.     'Check to see if length is more than 1 to avoid error or use 'On Error Resume Next'
  3.     If Len(Text1.Text) > 0 Then
  4.  
  5.         'Remove Last Character
  6.         Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
  7.  
  8.         'Set focus back on text box
  9.         Text1.SetFocus
  10.  
  11.         'Set to end of line
  12.         Text1.SelStart = Len(Text1.Text) + 1
  13.     End If
  14. End Sub
  15.  
Well hope this helps.
Kind Regards
Devon.
Mar 21 '07 #4

P: 1
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim j As Integer
  3.  
  4. j = Len(Text1.Text)
  5. If j <> 0 Then
  6. Text1.Text = Left(Text1.Text, j - 1)
  7. End If
  8. End Sub
Feb 18 '14 #5

Post your reply

Sign in to post your reply or Sign up for a free account.