Imports System.Math
Public Class pthouge
Inherits System.Windows.Forms.Form
Dim a As Double
Dim b As Double
Dim operator1 As Single
Dim operator2 As Single
Dim operator3 As Single
Dim operator4 As Single
Dim operator5 As Single
Private Sub ad1()
If (operator2 = 1 Or operator2 = 3) And operator5 = 1 Then
b = Val(TextBox1.Text)
TextBox1.Text = a
operator4 = 1
operator5 = 0
Call equalis()
End If
operator1 = 1
operator2 = 1
operator3 = 0
operator4 = 0
a = TextBox1.Text
End Sub
Private Sub small1()
If (operator2 = 1 Or operator2 = 3) And operator5 = 1 Then
b = Val(TextBox1.Text)
TextBox1.Text = a
operator4 = 1
operator5 = 0
Call equalis()
End If
operator1 = 2
operator2 = 1
operator3 = 0
operator4 = 0
a = TextBox1.Text
End Sub
Private Sub chen1()
If (operator2 = 1 Or operator2 = 3) And operator5 = 1 Then
b = Val(TextBox1.Text)
TextBox1.Text = a
operator4 = 1
operator5 = 0
Call equalis()
End If
operator1 = 3
operator2 = 1
operator3 = 0
operator4 = 0
a = TextBox1.Text
End Sub
Private Sub avg1()
If (operator2 = 1 Or operator2 = 3) And operator5 = 1 Then
b = Val(TextBox1.Text)
TextBox1.Text = a
operator4 = 0
operator5 = 0
Call equalis()
End If
operator1 = 4
operator2 = 1
operator3 = 0
operator4 = 0
a = TextBox1.Text
End Sub
Private Sub zero1()
If operator2 = 2 Then
Call cls()
TextBox1.Text = "0."
End If
If operator2 = 1 Then
TextBox1.Text = "0."
operator2 = 3
operator5 = 1
End If
If (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 And TextBox1.Text = "0." Then
ElseIf (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 Then
TextBox1.SelectionLength = TextBox1.TextLength - 1
TextBox1.Text = TextBox1.SelectedText
TextBox1.Text = TextBox1.Text & "0."
ElseIf (operator2 = 3 Or operator2 = 0) And (InStr(Val(TextBox1.Text), ".") <> 0 Or operator3 = 1) Then
TextBox1.Text = TextBox1.Text & "0"
End If
End Sub
Private Sub one1()
If operator2 = 2 Then
Call cls()
TextBox1.Text = "0."
End If
If operator2 = 1 Then
TextBox1.Text = "0."
operator2 = 3
operator5 = 1
End If
If (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 And TextBox1.Text = "0." Then
TextBox1.Text = "1."
ElseIf (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 Then
TextBox1.SelectionLength = TextBox1.TextLength - 1
TextBox1.Text = TextBox1.SelectedText
TextBox1.Text = TextBox1.Text & "1."
ElseIf (operator2 = 3 Or operator2 = 0) And (InStr(Val(TextBox1.Text), ".") <> 0 Or operator3 = 1) Then
TextBox1.Text = TextBox1.Text & "1"
End If
End Sub
Private Sub two1()
If operator2 = 2 Then
Call cls()
TextBox1.Text = "0."
End If
If operator2 = 1 Then
TextBox1.Text = "0."
operator2 = 3
operator5 = 1
End If
If (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 And TextBox1.Text = "0." Then
TextBox1.Text = "2."
ElseIf (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 Then
TextBox1.SelectionLength = TextBox1.TextLength - 1
TextBox1.Text = TextBox1.SelectedText
TextBox1.Text = TextBox1.Text & "2."
ElseIf (operator2 = 3 Or operator2 = 0) And (InStr(Val(TextBox1.Text), ".") <> 0 Or operator3 = 1) Then
TextBox1.Text = TextBox1.Text & "2"
End If
End Sub
Private Sub three1()
If operator2 = 2 Then
Call cls()
TextBox1.Text = "0."
End If
If operator2 = 1 Then
TextBox1.Text = "0."
operator2 = 3
operator5 = 1
End If
If (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 And TextBox1.Text = "0." Then
TextBox1.Text = "3."
ElseIf (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 Then
TextBox1.SelectionLength = TextBox1.TextLength - 1
TextBox1.Text = TextBox1.SelectedText
TextBox1.Text = TextBox1.Text & "3."
ElseIf (operator2 = 3 Or operator2 = 0) And (InStr(Val(TextBox1.Text), ".") <> 0 Or operator3 = 1) Then
TextBox1.Text = TextBox1.Text & "3"
End If
End Sub
Private Sub four1()
If operator2 = 2 Then
Call cls()
TextBox1.Text = "0."
End If
If operator2 = 1 Then
TextBox1.Text = "0."
operator2 = 3
operator5 = 1
End If
If (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 And TextBox1.Text = "0." Then
TextBox1.Text = "4."
ElseIf (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 Then
TextBox1.SelectionLength = TextBox1.TextLength - 1
TextBox1.Text = TextBox1.SelectedText
TextBox1.Text = TextBox1.Text & "4."
ElseIf (operator2 = 3 Or operator2 = 0) And (InStr(Val(TextBox1.Text), ".") <> 0 Or operator3 = 1) Then
TextBox1.Text = TextBox1.Text & "4"
End If
End Sub
Private Sub five1()
If operator2 = 2 Then
Call cls()
TextBox1.Text = "0."
End If
If operator2 = 1 Then
TextBox1.Text = "0."
operator2 = 3
operator5 = 1
End If
If (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 And TextBox1.Text = "0." Then
TextBox1.Text = "5."
ElseIf (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 Then
TextBox1.SelectionLength = TextBox1.TextLength - 1
TextBox1.Text = TextBox1.SelectedText
TextBox1.Text = TextBox1.Text & "5."
ElseIf (operator2 = 3 Or operator2 = 0) And (InStr(Val(TextBox1.Text), ".") <> 0 Or operator3 = 1) Then
TextBox1.Text = TextBox1.Text & "5"
End If
End Sub
Private Sub six1()
If operator2 = 2 Then
Call cls()
TextBox1.Text = "0."
End If
If operator2 = 1 Then
TextBox1.Text = "0."
operator2 = 3
operator5 = 1
End If
If (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 And TextBox1.Text = "0." Then
TextBox1.Text = "6."
ElseIf (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 Then
TextBox1.SelectionLength = TextBox1.TextLength - 1
TextBox1.Text = TextBox1.SelectedText
TextBox1.Text = TextBox1.Text & "6."
ElseIf (operator2 = 3 Or operator2 = 0) And (InStr(Val(TextBox1.Text), ".") <> 0 Or operator3 = 1) Then
TextBox1.Text = TextBox1.Text & "6"
End If
End Sub
Private Sub seven1()
If operator2 = 2 Then
Call cls()
TextBox1.Text = "0."
End If
If operator2 = 1 Then
TextBox1.Text = "0."
operator2 = 3
operator5 = 1
End If
If (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 And TextBox1.Text = "0." Then
TextBox1.Text = "7."
ElseIf (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 Then
TextBox1.SelectionLength = TextBox1.TextLength - 1
TextBox1.Text = TextBox1.SelectedText
TextBox1.Text = TextBox1.Text & "7."
ElseIf (operator2 = 3 Or operator2 = 0) And (InStr(Val(TextBox1.Text), ".") <> 0 Or operator3 = 1) Then
TextBox1.Text = TextBox1.Text & "7"
End If
End Sub
Private Sub eight1()
If operator2 = 2 Then
Call cls()
TextBox1.Text = "0."
End If
If operator2 = 1 Then
TextBox1.Text = "0."
operator2 = 3
operator5 = 1
End If
If (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 And TextBox1.Text = "0." Then
TextBox1.Text = "8."
ElseIf (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 Then
TextBox1.SelectionLength = TextBox1.TextLength - 1
TextBox1.Text = TextBox1.SelectedText
TextBox1.Text = TextBox1.Text & "8."
ElseIf (operator2 = 3 Or operator2 = 0) And (InStr(Val(TextBox1.Text), ".") <> 0 Or operator3 = 1) Then
TextBox1.Text = TextBox1.Text & "8"
End If
End Sub
Private Sub nine1()
If operator2 = 2 Then
Call cls()
TextBox1.Text = "0."
End If
If operator2 = 1 Then
TextBox1.Text = "0."
operator2 = 3
operator5 = 1
End If
If (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 And TextBox1.Text = "0." Then
TextBox1.Text = "9."
ElseIf (operator2 = 3 Or operator2 = 0) And InStr(Val(TextBox1.Text), ".") = 0 And operator3 = 0 Then
TextBox1.SelectionLength = TextBox1.TextLength - 1
TextBox1.Text = TextBox1.SelectedText
TextBox1.Text = TextBox1.Text & "9."
ElseIf (operator2 = 3 Or operator2 = 0) And (InStr(Val(TextBox1.Text), ".") <> 0 And operator3 = 1) Then
TextBox1.Text = TextBox1.Text & "9"
End If
End Sub
Private Sub cls()
a = 0
b = 0
operator1 = 0 '运算符
operator2 = 0 '判断有无运算符 0,无运算符 1,有运算符,2,运算符被用
operator3 = 0 '判断有无小数点
operator4 = 0 '=号的运算方法:0表示输入运算符后还未计算过,1表示运算过
operator5 = 0 '多次点击运算符的计算方法
TextBox1.Text = 0
End Sub
Private Sub equalis()
If operator4 = 1 Then
If operator1 = 1 Then
TextBox1.Text = Val(TextBox1.Text) + b
ElseIf operator1 = 2 Then
TextBox1.Text = Val(TextBox1.Text) - b
ElseIf operator1 = 3 Then
TextBox1.Text = Val(TextBox1.Text) * b
ElseIf operator1 = 4 Then
TextBox1.Text = Val(TextBox1.Text) / b
End If
If InStr(TextBox1.Text, ".") = 0 Then
TextBox1.Text = TextBox1.Text & "."
End If
End If
If operator4 = 0 Then
If operator1 = 0 Then
a = TextBox1.Text
End If
If operator1 = 1 Then
TextBox1.Text = Val(TextBox1.Text) + a
ElseIf operator1 = 2 Then
TextBox1.Text = a - Val(TextBox1.Text)
ElseIf operator1 = 3 Then
TextBox1.Text = Val(TextBox1.Text) * a
ElseIf operator1 = 4 Then
TextBox1.Text = a / Val(TextBox1.Text)
End If
If InStr(TextBox1.Text, ".") = 0 Then
TextBox1.Text = TextBox1.Text & "."
End If
End If
a = TextBox1.Text
End Sub