Simple Calculator in vb.net

Public Class Form1

'' Declaring the variables

Dim str As String
Dim str1 As Double
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim a As Integer
Dim str2 As Double

' Drag and drop buttons for the all the basic functions of the calculator with 'all digits (0 to 9).
'Change the properties including name and text

'The following code for plusButton

Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPLus.Click
str1 = Val(txtdisplay.Text)
txtdisplay.Text = " "
str = btnPLus.Text
End Sub

'The following code for EqualButton

Private Sub btnEqual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEqual.Click
'str = Val(txtdisplay.Text)
'str1 = Val(txtdisplay.Text)
str2 = Val(txtdisplay.Text)

If str = "+" Then
txtdisplay.Text = str1 + str2
End If

If str = "-" Then
txtdisplay.Text = str1 - str2
End If

If str = "*" Then
txtdisplay.Text = str1 * str2
End If

If str = "/" Then
txtdisplay.Text = str1 / str2
End If

End Sub


'The following code for "DigitOne" Button

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


'The following code for "DigitTwo" Button


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


x = CInt(btnTwo.Text)



End Sub


'The following code for "DigitThree" Button


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

y = CInt(btnThree.Text)

End Sub


'The following code for "DigitFour" Button


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


a = CInt(btnFour.Text)


End Sub


'The following code for "DigitFive" Button


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

y = CInt(btnFive.Text)


End Sub


'The following code for "DigitSix" Button


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

a = CInt(btnSix.Text)


End Sub


'The following code for "DigitSeven" Button


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

y = CInt(btnSeven.Text)

End Sub

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

a = CInt(btnEight.Text)



End Sub


'The following code for "DigitEight" Button


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

y = CInt(btnNine.Text)


End Sub


'The following code for "DigitNine" Button


Private Sub btnTen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTen.Click
txtdisplay.Text = btnTen.Text


a = CInt(btnTen.Text)

End Sub


'The following code for thirtButton


Private Sub btnThirt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThirt.Click
txtdisplay.Clear()


End Sub



'The following code for MinusButton

Private Sub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click
str1 = Val(txtdisplay.Text)
txtdisplay.Text = " "
str = btnMinus.Text
End Sub


'The following code for MultiplyButton


Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click
str1 = Val(txtdisplay.Text)
txtdisplay.Text = " "
str = btnMultiply.Text
End Sub



'The following code for "DigitZeroZero" Button

Private Sub btnZeroZero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZeroZero.Click
txtdisplay.Text = txtdisplay.Text & btnZeroZero.Text
End Sub


'The following code for DivideButton


Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click
str1 = Val(txtdisplay.Text)
txtdisplay.Text = " "
str = btnDivide.Text
End Sub


'The following code for PointButton


Private Sub btnPoint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPoint.Click
txtdisplay.Text = txtdisplay.Text & btnPoint.Text
End Sub
End Class


Attachments

Comments

Guest Author: shashi24 Jan 2013

plz tell me script calculator in powerbuild

Guest Author: Sajju11 Mar 2013

when you click equal what value should be stored in three variables
if you assign like that all the variables will contain same value.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: