Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class calcArea
- 'Operands
- Private num1 As Double
- Private num2 As Double
- 'Temporary values
- Private tempValue As Double
- 'Memory storage
- Private Memory As Double
- 'True if "," is use else false
- Private hasDecimal As Boolean
- Private inputStatus As Boolean
- Private clearText As Boolean
- 'Operator
- Private calcFunction As String
- #Region "Number Buttons"
- Private Sub Btn_0_Click(sender As Object, e As EventArgs) Handles btn_0.Click
- If inputStatus = False Then
- If lbl_input.Text.Length >= 1 Then
- lbl_input.Text += btn_0.Text
- End If
- End If
- End Sub
- Private Sub Btn_1_Click(sender As Object, e As EventArgs) Handles btn_1.Click
- If inputStatus = False Then
- lbl_input.Text += btn_1.Text
- Else
- lbl_input.Text = btn_1.Text
- inputStatus = False
- End If
- End Sub
- Private Sub Btn_2_Click(sender As Object, e As EventArgs) Handles btn_2.Click
- If inputStatus = False Then
- lbl_input.Text += btn_2.Text
- Else
- lbl_input.Text = btn_2.Text
- inputStatus = False
- End If
- End Sub
- Private Sub Btn_3_Click(sender As Object, e As EventArgs) Handles btn_3.Click
- If inputStatus = False Then
- lbl_input.Text += btn_3.Text
- Else
- lbl_input.Text = btn_3.Text
- inputStatus = False
- End If
- End Sub
- Private Sub Btn_4_Click(sender As Object, e As EventArgs) Handles btn_4.Click
- If inputStatus = False Then
- lbl_input.Text += btn_4.Text
- Else
- lbl_input.Text = btn_4.Text
- inputStatus = False
- End If
- End Sub
- Private Sub Btn_5_Click(sender As Object, e As EventArgs) Handles btn_5.Click
- If inputStatus = False Then
- lbl_input.Text += btn_5.Text
- Else
- lbl_input.Text = btn_5.Text
- inputStatus = False
- End If
- End Sub
- Private Sub Btn_6_Click(sender As Object, e As EventArgs) Handles btn_6.Click
- If inputStatus = False Then
- lbl_input.Text += btn_6.Text
- Else
- lbl_input.Text = btn_6.Text
- inputStatus = False
- End If
- End Sub
- Private Sub Btn_7_Click(sender As Object, e As EventArgs) Handles btn_7.Click
- If inputStatus = False Then
- lbl_input.Text += btn_7.Text
- Else
- lbl_input.Text = btn_7.Text
- inputStatus = False
- End If
- End Sub
- Private Sub Btn_8_Click(sender As Object, e As EventArgs) Handles btn_8.Click
- If inputStatus = False Then
- lbl_input.Text += btn_8.Text
- Else
- lbl_input.Text = btn_8.Text
- inputStatus = False
- End If
- End Sub
- Private Sub Btn_9_Click(sender As Object, e As EventArgs) Handles btn_9.Click
- If inputStatus = False Then
- lbl_input.Text += btn_9.Text
- Else
- lbl_input.Text = btn_9.Text
- inputStatus = False
- End If
- End Sub
- #End Region
- #Region "Calculation Buttons"
- Private Sub Btn_plus_Click(sender As Object, e As EventArgs) Handles btn_plus.Click
- If lbl_input.Text.Length <> 0 Then
- If calcFunction = String.Empty Then
- num1 = CDbl(lbl_input.Text)
- lbl_input.Text = String.Empty
- Else
- CalculateTotals()
- End If
- calcFunction = "Add"
- hasDecimal = False
- End If
- End Sub
- Private Sub Btn_minus_Click(sender As Object, e As EventArgs) Handles btn_minus.Click
- If lbl_input.Text.Length <> 0 Then
- If calcFunction = String.Empty Then
- num1 = CDbl(lbl_input.Text)
- lbl_input.Text = String.Empty
- Else
- CalculateTotals()
- End If
- calcFunction = "Substract"
- hasDecimal = False
- End If
- End Sub
- Private Sub Btn_slash_Click(sender As Object, e As EventArgs) Handles btn_slash.Click
- If lbl_input.Text.Length <> 0 Then
- If calcFunction = String.Empty Then
- num1 = CDbl(lbl_input.Text)
- lbl_input.Text = String.Empty
- Else
- CalculateTotals()
- End If
- calcFunction = "Divide"
- hasDecimal = False
- End If
- End Sub
- Private Sub Btn_mpp_Click(sender As Object, e As EventArgs) Handles btn_mpp.Click
- If lbl_input.Text.Length <> 0 Then
- If calcFunction = String.Empty Then
- num1 = CDbl(lbl_input.Text)
- lbl_input.Text = String.Empty
- Else
- CalculateTotals()
- End If
- calcFunction = "Multiply"
- hasDecimal = False
- End If
- End Sub
- Private Sub Btn_upper_Click(sender As Object, e As EventArgs) Handles btn_upper.Click
- If lbl_input.Text.Length <> 0 Then
- If calcFunction = String.Empty Then
- num1 = CDbl(lbl_input.Text)
- lbl_input.Text = String.Empty
- Else
- CalculateTotals()
- End If
- calcFunction = "PowerOf"
- hasDecimal = False
- End If
- End Sub
- Private Sub Btn_sqrt_Click(sender As Object, e As EventArgs) Handles btn_sqrt.Click
- If lbl_input.Text.Length <> 0 Then
- tempValue = CDbl(lbl_input.Text)
- tempValue = System.Math.Sqrt(tempValue)
- lbl_input.Text = CStr(tempValue)
- hasDecimal = False
- End If
- End Sub
- Private Sub Btn_equal_Click(sender As Object, e As EventArgs) Handles btn_equal.Click
- If lbl_input.Text.Length <> 0 AndAlso num1 <> 0 Then
- CalculateTotals()
- calcFunction = ""
- hasDecimal = False
- End If
- End Sub
- Private Sub Btn_below_Click(sender As Object, e As EventArgs) Handles btn_below.Click
- If lbl_input.Text.Length <> 0 Then
- tempValue = CDbl(lbl_input.Text)
- tempValue = 1 / tempValue
- lbl_input.Text = CStr(tempValue)
- hasDecimal = False
- End If
- End Sub
- Private Sub Btn_plusminus_Click(sender As Object, e As EventArgs) Handles btn_plusminus.Click
- If inputStatus = False Then
- If lbl_input.Text.Length > 0 Then
- tempValue = -1 * CDbl(lbl_input.Text)
- lbl_input.Text = CStr(tempValue)
- End If
- End If
- End Sub
- #End Region
- #Region "Other Buttons"
- Private Sub Btn_CE_Click(sender As Object, e As EventArgs) Handles btn_CE.Click
- lbl_input.Text = String.Empty
- hasDecimal = False
- End Sub
- Private Sub Btn_C_Click(sender As Object, e As EventArgs) Handles btn_C.Click
- lbl_input.Text = String.Empty
- num1 = 0
- num2 = 0
- calcFunction = String.Empty
- hasDecimal = False
- End Sub
- Private Sub Btn_backspace_Click(sender As Object, e As EventArgs) Handles btn_backspace.Click
- Dim str As String
- Dim loc As Integer
- If lbl_input.Text.Length > 0 Then
- str = lbl_input.Text.Chars(lbl_input.Text.Length - 1)
- If str = "." Then
- hasDecimal = False
- End If
- loc = lbl_input.Text.Length
- lbl_input.Text = lbl_input.Text.Remove(loc - 1, 1)
- End If
- End Sub
- Private Sub Btn_dot_Click(sender As Object, e As EventArgs) Handles btn_dot.Click
- If Not inputStatus Then
- If Not hasDecimal Then
- If lbl_input.Text.Length >= 1 Then
- If Not lbl_input.Text = "0" Then
- lbl_input.Text += ","
- hasDecimal = True
- End If
- Else
- lbl_input.Text = "0"
- End If
- End If
- End If
- End Sub
- #End Region
- #Region "Helpers"
- Private Sub CalculateTotals()
- num2 = CDbl(lbl_input.Text)
- Select Case calcFunction
- Case "Add"
- num1 = num1 + num2
- Case "Substract"
- num1 = num1 - num2
- Case "Divide"
- num1 = num1 / num2
- Case "Multiply"
- num1 = num1 * num2
- Case "PowerOf"
- num1 = System.Math.Pow(num1, num2)
- End Select
- lbl_input.Text = CStr(num1)
- inputStatus = True
- End Sub
- #End Region
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement