Вы находитесь на странице: 1из 4

Button1 - Back Space

Button2 - C
Button3 - 1
Button4 - 2
Button5 - 3
Button6 - /
Button7 - x^
Button8 - 4
Button9 - 5
Button10 - 6
Button11 - *
Button12 - Sqrt
Button13 - 7
Button14 - 8
Button15 - 9
Button16 - Button17 - 1/x
Button18 - 0
Button19 - +/Button20 - .
Button21 - +
Button22 - =

Dim Operand1 As Double


Dim Operand2 As Double
Dim [Operator] As String
Dim hasDecimal As Boolean
Dim tmpValue As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Declare locals needed
Dim str As String
Dim loc As Integer
'Make sure the text length is > 1
If Textbox1.Text.Length > 0 Then
'Get the next to last character
str = Textbox1.Text.Chars(Textbox1.Text.Length - 1)
'Check if its a decimal
If str = "." Then
'If it is toggle the hasDecimal flag
End If
'Get the length of the string
loc = Textbox1.Text.Length
'Remove the last character, incrementing by 1
Textbox1.Text = Textbox1.Text.Remove(loc - 1, 1)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Textbox1.Text = ""
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Textbox1.Text = Textbox1.Text & sender.text

End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Textbox1.Text = Textbox1.Text & sender.text
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Textbox1.Text = Textbox1.Text & sender.text
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button8.Click
Textbox1.Text = Textbox1.Text & sender.text
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button9.Click
Textbox1.Text = Textbox1.Text & sender.text
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button10.Click
Textbox1.Text = Textbox1.Text & sender.text
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button13.Click
Textbox1.Text = Textbox1.Text & sender.text
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button14.Click
Textbox1.Text = Textbox1.Text & sender.text
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button15.Click
Textbox1.Text = Textbox1.Text & sender.text
End Sub
Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button18.Click
Textbox1.Text = Textbox1.Text & sender.text
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
Operand1 = Val(Textbox1.Text)
Textbox1.Text = ""
Textbox1.Focus()
[Operator] = "/"
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button7.Click
Operand1 = Val(Textbox1.Text)
Textbox1.Text = ""
Textbox1.Focus()
[Operator] = "^"
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button11.Click
Operand1 = Val(Textbox1.Text)

Textbox1.Text = ""
Textbox1.Focus()
[Operator] = "*"
End Sub
Private Sub Button12_Click(ByVal sender As System.Object,
System.EventArgs) Handles Button12.Click
'Make sure the input box has a value
If Textbox1.Text.Length <> 0 Then
'Assign our variable the value in the input box
tmpValue = CType(Textbox1.Text, Double)
'Perform the square root
tmpValue = System.Math.Sqrt(tmpValue)
'Display the results in the input box
Textbox1.Text = CType(tmpValue, String)
'Clear the decimal flag
hasDecimal = False
End If
End Sub
Private Sub Button16_Click(ByVal sender As System.Object,
System.EventArgs) Handles Button16.Click
Operand1 = Val(Textbox1.Text)
Textbox1.Text = ""
Textbox1.Focus()
[Operator] = "-"
End Sub
Private Sub Button17_Click(ByVal sender As System.Object,
System.EventArgs) Handles Button17.Click
Dim convert As Single
If Textbox1.Text <> 0 Then
convert = 1 / Val(Textbox1.Text)
Textbox1.Text = convert
End If
End Sub
Private Sub Button19_Click(ByVal sender As System.Object,
System.EventArgs) Handles Button19.Click
Textbox1.Text = -1 * Textbox1.Text
End Sub
Private Sub Button20_Click(ByVal sender As System.Object,
System.EventArgs) Handles Button20.Click
If InStr(Textbox1.Text, ".") > 0 Then
Exit Sub
Else
Textbox1.Text = Textbox1.Text & "."
End If
End Sub
Private Sub Button21_Click(ByVal sender As System.Object,
System.EventArgs) Handles Button21.Click
Operand1 = Val(Textbox1.Text)
Textbox1.Text = ""
Textbox1.Focus()
[Operator] = "+"
End Sub
Private Sub Button22_Click(ByVal sender As System.Object,
System.EventArgs) Handles Button22.Click
Dim Result As Double
Operand2 = Val(Textbox1.Text)
'If [Operator] = "+" Then
'
Result = Operand1 + Operand2
'ElseIf [Operator] = "-" Then

ByVal e As

ByVal e As

ByVal e As

ByVal e As

ByVal e As

ByVal e As

ByVal e As

'
Result = Operand1 'ElseIf [Operator] = "/"
'
Result = Operand1 /
'ElseIf [Operator] = "*"
'
Result = Operand1 *
'End If

Operand2
Then
Operand2
Then
Operand2

Select Case [Operator]


Case "+"
Result = Operand1 + Operand2
Textbox1.Text = Result.ToString()
Case "-"
Result = Operand1 - Operand2
Textbox1.Text = Result.ToString()
Case "/"
Result = Operand1 / Operand2
Textbox1.Text = Result.ToString()
Case "*"
Result = Operand1 * Operand2
Textbox1.Text = Result.ToString()
Case "^"
Result = Operand1 ^ Operand2
Textbox1.Text = Result.ToString()
Case "%"
Result = Operand1 * 1 / 100
Textbox1.Text = Result.ToString()
End Select
Textbox1.Text = Result.ToString()
End Sub
End Class

Вам также может понравиться