Shayna Shayna - 25 days ago 5x Question

How do I add text to a textbox? Not replace

I'd like to know how to add text to a textbox by the use of an event, for example the click of a button.

Now when I say add I literally mean add, not replace.


TextBox1.Text = ""
because all that does it change all the text in the textbox to whatever is in the quotes, I want to add text not replace it so for example if I had "ABC" typed into my textbox and I want to add the letter "D" to it without replacing the whole text what would I have to do?

Thanks in advance.


Use the concatenation operator to concatenate your new text with the old one:

TextBox1.Text &= "D" 'Results in "ABCD"

or use the TextBox.AppendText() method:

TextBox1.AppendText("D") 'Also results in "ABCD"

Note that my first example is the same as doing:

TextBox1.Text = TextBox1.Text & "D"

Also see this Stack Overflow answer about why you should always concatenate strings with the ampersand (&) instead of the plus sign (+).