Jack Ryan

Jack Ryan

  • NA
  • 1
  • 0

{help} basic calculator in visual basic 2008

Dec 14 2009 3:12 PM
Hello. I am new to visual basic 2008, and i started with simple project-calculator. I made it to the point where "+" sign works, and "=" sign execute the command of "+" sign. Now i try to make "-" sign work: the problem is, idk how to bind it with "=". Here is the code:
 Public Class Form1
Dim total1 As Integer
Dim total2 As Integer

Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click
txtDisplay.Text = txtDisplay.Text & btnOne.Text
End Sub

Private Sub btnTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTwo.Click
txtDisplay.Text = txtDisplay.Text & btnTwo.Text
End Sub

Private Sub btnThree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThree.Click
txtDisplay.Text = txtDisplay.Text & btnThree.Text
End Sub

Private Sub btnFour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFour.Click
txtDisplay.Text = txtDisplay.Text & btnFour.Text
End Sub

Private Sub btnFive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFive.Click
txtDisplay.Text = txtDisplay.Text & btnFive.Text
End Sub

Private Sub btnSix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSix.Click
txtDisplay.Text = txtDisplay.Text & btnSix.Text
End Sub

Private Sub btnSeven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeven.Click
txtDisplay.Text = txtDisplay.Text & btnSeven.Text
End Sub

Private Sub btnEight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEight.Click
txtDisplay.Text = txtDisplay.Text & btnEight.Text
End Sub

Private Sub btnNine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNine.Click
txtDisplay.Text = txtDisplay.Text & btnNine.Text
End Sub

Private Sub btnZero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZero.Click
txtDisplay.Text = txtDisplay.Text & btnZero.Text
End Sub

Private Sub cmdPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlus.Click
total1 = total1 + Val(txtDisplay.Text)
txtDisplay.Clear()
End Sub

Private Sub cmdEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEquals.Click
total2 = total1 + Val(txtDisplay.Text)
txtDisplay.Text = total2
total1 = 0

End Sub

Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click
txtDisplay.Clear()
End Sub


Private Sub cmdMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMinus.Click
total1 = total1 - Val(txtDisplay.Text)
txtDisplay.Clear()
End Sub
End Class
Question is:
how can i use "if" (conditional) statement in this code:
 Private Sub cmdEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEquals.Click
total2 = total1 + Val(txtDisplay.Text)
txtDisplay.Text = total2
total1 = 0
And do i need to add another value like:
 Dim total3 As Integer
and use it as a "-" button:
 Private Sub cmdMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMinus.Click
total3 = total3 - Val(txtDisplay.Text)
txtDisplay.Clear()
End Sub
????
Please Help.
Thank you.

Answers (1)