Add text to a textbox, not erase then add new text

stefonalfaro

Member
Joined
Dec 3, 2007
Messages
16
Programming Experience
Beginner
Ok im making my first program and its a calculator with alot of fun options. Let me explain a little. When my button1 is presses
VB.NET:
txtanswer.text="1"
and when button2 is presses
VB.NET:
txtanswer.text="2"
and so on and so on.... but what happens is if I want to write down the number 12 I would normally push the 1 and then the 2. But when I do this here It writes down 1 then when I push 2 it erase the current text from txtanswer.text then add a 2. How can I make it so it just keeps on adding more text so I can write a 2 digit number?

Just so you know my txtanswer is a textbox
 
Last edited:
you can try the following code. Chage the value in the quote according to the button pressed.
VB.NET:
txtAnswer.Text = txtAnswer.Text + "2"
 
There's also:
txtAnswer.AppendText(CType(sender), Button).Text)

I've used CType(sender), Button).Text to get whatever "number" is on whatever button they click, this way you can have all of your buttons have 1 click event and you use CType(sender), Button).Text to add whatever number is on the button clicked

Another alternative is to add the number to the Tag property and use Cstr(CType(sender), Button).Tag)
 
VB.NET:
txtAnswer.AppendText("2")
You can also add the number bits to a private string variable and each time push this to display.
 
Back
Top