VB.NET Calculator

Associate
Joined
6 Dec 2007
Posts
2,103
Hi guys, you're probably going to to laugh at this, but I've gone wrong somewhere in my code for a calculator.

Basically, it'll add two or more numbers if you do something like 2 + 2 + 2 = 6, but if you do something like (2 + 2), and then hit equals to get 4, and then add 2 to that, It'll give some silly results. I think it's my equals button that is messed up, but I can't be sure.

Can anyone help? Will post snippets of code as required. Thanks :)
 
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click

firstNum = firstNum + Convert.ToDecimal(txtNumbers.Text)

txtNumbers.Clear()

End Sub

Private Sub cmdEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEquals.Click

secondNum = firstNum + Convert.ToDecimal(txtNumbers.Text)
txtNumbers.Clear()
txtNumbers.Text = Convert.ToString(secondNum)

End Sub

This be the code for the add and equals buttons. Thanks guys, let me know if anything else is needed :)
 
Back
Top Bottom