1
votes

I have a textbox, textbox1, whose ReadOnly property is set to true. It is somewhat like an on-screen keyboard. When the user presses a button, I can add characters by using:

Textbox1.Text = Textbox1.Text & A

But, when the user wants to remove the text, which should work exactly like the Backspace key, the last character should be removed from the textbox.

I am ready to give up normal textbox and use richtextbox if there is any way ahead with the rich one.

How to remove last character of a textbox with a button?

3

3 Answers

5
votes

The previously suggested SubString method is what I would have posted too. However, there is an alternative. The Remove method works by removing every character after the given index. For instance:

TextBox1.Text = Textbox1.Text.Remove(TextBox1.Text.Length - 1)
2
votes

You can use the SubString method to get all but the last character, for instance:

TextBox1.Text = TextBox1.Text.SubString(0, TextBox1.Text.Length - 1)
-1
votes

The above functions such as Substring and Remove are not executed in Visual Basic 6 (or earlier versions). I recommend to use Mid function.

For instance,in this example last character of Hello is deleted and rest of word is saved in Text1

Text1=Mid("Hello",1, Len("Hello") - 1)

and result is Text1=Hell