Anda di halaman 1dari 6

For no.

1 -9
If (blnInputStatus AndAlso txtInput.Text <> "0") Or blnDecimalPoint Then
txtInput.Text += Button2.Text
Else
txtInput.Text = Button2.Text
blnInputStatus = True

End If

If (blnInputStatus AndAlso txtInput.Text <> "0") Or blnDecimalPoint Then


txtInput.Text += Button3.Text
Else
txtInput.Text = Button3.Text
blnInputStatus = True

End If

If (blnInputStatus AndAlso txtInput.Text <> "0") Or blnDecimalPoint Then


txtInput.Text += Button4.Text
Else
txtInput.Text = Button4.Text
blnInputStatus = True

End If

If (blnInputStatus AndAlso txtInput.Text <> "0") Or blnDecimalPoint Then


txtInput.Text += Button5.Text
Else
txtInput.Text = Button5.Text
blnInputStatus = True

End If

If (blnInputStatus AndAlso txtInput.Text <> "0") Or blnDecimalPoint Then


txtInput.Text += Button6.Text
Else
txtInput.Text = Button6.Text
blnInputStatus = True

End If

If (blnInputStatus AndAlso txtInput.Text <> "0") Or blnDecimalPoint Then


txtInput.Text += Button7.Text
Else
txtInput.Text = Button7.Text
blnInputStatus = True

End If
If (blnInputStatus AndAlso txtInput.Text <> "0") Or blnDecimalPoint Then
txtInput.Text += Button8.Text
Else
txtInput.Text = Button8.Text
blnInputStatus = True

End If

If (blnInputStatus AndAlso txtInput.Text <> "0") Or blnDecimalPoint Then


txtInput.Text += Button9.Text
Else
txtInput.Text = Button9.Text
blnInputStatus = True

End If

If (blnInputStatus AndAlso txtInput.Text <> "0") Or blnDecimalPoint Then


txtInput.Text += Button10.Text
Else
txtInput.Text = Button10.Text
blnInputStatus = True

End If

For no 0
If blnInputStatus Then
'To prevent multuple zeroes from appearing if 0 is the first digit.
If txtInput.Text.Length >= 1 AndAlso txtInput.Text <> "0" Then
txtInput.Text += Button1.Text
'This is to allow 0 to be added after after the decimal point.
ElseIf blnDecimalPoint Then
txtInput.Text += Button1.Text
End If
End If

For decimal point


'To make sure that no decimal point has already been input.
If Not blnDecimalPoint Then
'For values > 0 but < 1.
If txtInput.Text.Length < 1 Then
txtInput.Text = "0."
Else
txtInput.Text += "."
End If
End If
For Operator
If txtInput.Text.Length <> 0 Then
'Check the value of the function flag.
If strCalculate = String.Empty Then
'Assign the value in the input box to the holder.
dblValue1 = CType(txtInput.Text, Double)
txtInput.Text = "0"
Else
'Call the CalculateTotals method.
CalculateTotals()

End If

'Assign a value to the function flag.


strCalculate = "Add"

'Toggle the decimal flag.


blnDecimalPoint = False
End If

For Equal Button


If txtInput.Text.Length <> 0 Then
CalculateTotals()
strCalculate = String.Empty
blnDecimalPoint = False
End If

For Exponential Button


If txtInput.Text.Length <> 0 Then
If strCalculate = String.Empty Then
dblValue1 = CType(txtInput.Text, Double)
txtInput.Text = "0"

Else
CalculateTotals()

End If

strCalculate = "Exponential"
blnDecimalPoint = False

End If
For square root button
If txtInput.Text < "0" Then
MsgBox("The root of a negative number is undefined!", 0, "WARNING!")
Exit Sub

End If

If txtInput.Text.Length <> 0 Then


dblTemp = CType(txtInput.Text, Double)
dblTemp = System.Math.Sqrt(dblTemp)
txtInput.Text = CType(dblTemp, String)
blnDecimalPoint = False

End If

For Reciprocal Button


If txtInput.Text.Length <> 0 Then
dblTemp = CType(txtInput.Text, Double)
dblTemp = 1 / dblTemp
txtInput.Text = CType(dblTemp, String)
blnDecimalPoint = False

End If

For potivie/negative button


If txtInput.Text.Length <> 0 Then
dblTemp = CType(txtInput.Text, Double)
dblTemp *= -1
txtInput.Text = CType(dblTemp, String)
End If

For clear all button


txtInput.Text = "0"
dblValue1 = 0
dblValue2 = 0
strCalculate = String.Empty
blnDecimalPoint = False

for clear button


txtInput.Text = "0"
blnDecimalPoint = False
For backspace
'Declare locals needed.
Dim str As String
Dim intNumbers As Integer = txtInput.Text.Length

If txtInput.Text.Length = 1 Or (txtInput.Text.Length = 2 AndAlso


txtInput.Text.StartsWith("-")) Then
txtInput.Text = "0"
Exit Sub

End If

If txtInput.Text.Length > 0 Then


'Get the next to last character.
str = txtInput.Text.Chars(txtInput.Text.Length - 2)
'Check if it's a decimal.
If str = "." Then
'If it is, thne toggle the blnDecimalPoint flag.
blnDecimalPoint = False
txtInput.Text = txtInput.Text.Remove(intNumbers - 2)
Exit Sub
End If

txtInput.Text = txtInput.Text.Remove(intNumbers - 1)

End If
End Sub

For calculate totals


dblValue2 = CType(txtInput.Text, Double)
Select Case strCalculate
Case "Add"
dblValue1 += dblValue2
Case "Subtract"
dblValue1 -= dblValue2
Case "Multiply"
dblValue1 *= dblValue2
Case "Divide"
If dblValue2 = 0 Then
MsgBox("You cannot divide by 0!", 0, "WARNING!")
Exit Sub
End If
dblValue1 /= dblValue2
Case "Exponential"
dblValue1 ^= dblValue2
End Select
txtInput.Text = CType(dblValue1, String)
blnInputStatus = False
'Variables to hold the operands.
Private dblValue1 As Double
Private dblValue2 As Double
'Variables to hold temporary values.
Private dblTemp As Double
'True if "." is used, otherwise false.
Private blnDecimalPoint As Boolean
Private blnInputStatus As Boolean
'Variable to hold Operator.
Private strCalculate As String

Anda mungkin juga menyukai