Public Class 計算機
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBox1.Enabled = False : TextBox2.Enabled = False : TextBox3.Enabled = False
        Me.KeyPreview = True
    End Sub
    Private Sub Form_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyCode
            Case Keys.NumPad1 : Button1.PerformClick() : Case Keys.NumPad2 : Button2.PerformClick() : Case Keys.NumPad3 : Button3.PerformClick() : Case Keys.NumPad4 : Button4.PerformClick()
            Case Keys.NumPad5 : Button5.PerformClick() : Case Keys.NumPad6 : Button6.PerformClick() : Case Keys.NumPad7 : Button7.PerformClick() : Case Keys.NumPad8 : Button8.PerformClick()
            Case Keys.NumPad9 : Button9.PerformClick() : Case Keys.NumPad0 : Button10.PerformClick() : Case Keys.Decimal : Button12.PerformClick() : Case Keys.D1 : Button1.PerformClick()
            Case Keys.D2 : Button2.PerformClick() : Case Keys.D3 : Button3.PerformClick() : Case Keys.D4 : Button4.PerformClick() : Case Keys.D5 : Button5.PerformClick()
            Case Keys.D6 : Button6.PerformClick() : Case Keys.D7 : Button7.PerformClick() : Case Keys.D8 : Button8.PerformClick() : Case Keys.D9 : Button9.PerformClick()
            Case Keys.D0 : Button10.PerformClick() : Case Keys.OemPeriod : Button12.PerformClick() : Case Keys.Delete : Button11.PerformClick() : Case Keys.Multiply : Button15.PerformClick()
            Case Keys.Subtract : Button14.PerformClick() : Case Keys.OemMinus : Button14.PerformClick() : Case Keys.Add : Button13.PerformClick() : Case Keys.Oemplus : Button13.PerformClick()
            Case Keys.Oem2 : Button16.PerformClick() : Case Keys.Divide : Button16.PerformClick()
        End Select
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If TextBox1.Text <> "" Then
            TextBox1.Text = TextBox1.Text & 1
        Else
            TextBox1.Text = 1
        End If
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If TextBox1.Text <> "" Then
            TextBox1.Text = TextBox1.Text & 2
        Else
            TextBox1.Text = 2
        End If
    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If TextBox1.Text <> "" Then
            TextBox1.Text = TextBox1.Text & 3
        Else
            TextBox1.Text = 3
        End If
    End Sub
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If TextBox1.Text <> "" Then
            TextBox1.Text = TextBox1.Text & 4
        Else
            TextBox1.Text = 4
        End If
    End Sub
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        If TextBox1.Text <> "" Then
            TextBox1.Text = TextBox1.Text & 5
        Else
            TextBox1.Text = 5
        End If
    End Sub
    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        If TextBox1.Text <> "" Then
            TextBox1.Text = TextBox1.Text & 6
        Else
            TextBox1.Text = 6
        End If
    End Sub
    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        If TextBox1.Text <> "" Then
            TextBox1.Text = TextBox1.Text & 7
        Else
            TextBox1.Text = 7
        End If
    End Sub
    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        If TextBox1.Text <> "" Then
            TextBox1.Text = TextBox1.Text & 8
        Else
            TextBox1.Text = 8
        End If
    End Sub
    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        If TextBox1.Text <> "" Then
            TextBox1.Text = TextBox1.Text & 9
        Else
            TextBox1.Text = 9
        End If
    End Sub
    Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
        If TextBox1.Text <> "" Then
            TextBox1.Text = TextBox1.Text & 0
        Else
            TextBox1.Text = 0
        End If
    End Sub
    Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
        If TextBox1.Text <> "" Then
            TextBox1.Text = TextBox1.Text & "."
        Else
            TextBox1.Text = "0."
        End If
    End Sub
    '----------------------------數字鍵盤---------------------------------------------------------------------------------------------------------------
    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
        Dim SS As Integer
        If TextBox1.Text <> "" Then
            TextBox1.Text = Int(Val(TextBox1.Text) / 10)
        ElseIf TextBox1.Text = "" And TextBox2.Text <> "" Then
            SS = Len(TextBox2.Text)
            TextBox2.Text = Strings.Left(TextBox2.Text, SS - 1)
        Else
            TextBox1.Text = ""
        End If

    End Sub
    Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click
        Button18.PerformClick()
        If TextBox1.Text <> "" And TextBox2.Text = "" Then
            TextBox2.Text = TextBox1.Text
            TextBox1.Text = ""
        End If
        If TextBox1.Text <> "" And TextBox2.Text <> "" Then
            TextBox2.Text = Val(TextBox2.Text) / Val(TextBox1.Text)
            TextBox1.Text = ""
        End If
        TextBox3.Text = "/"
    End Sub

    Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
        Button18.PerformClick()
        If TextBox1.Text <> "" And TextBox2.Text = "" Then
            TextBox2.Text = TextBox1.Text
            TextBox1.Text = ""
        End If
        If TextBox1.Text <> "" And TextBox2.Text <> "" Then
            TextBox2.Text = Val(TextBox1.Text) * Val(TextBox2.Text)
            TextBox1.Text = ""
        End If
        TextBox3.Text = "X"
    End Sub
    Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
        Button18.PerformClick()
        If TextBox1.Text <> "" And TextBox2.Text = "" Then
            TextBox2.Text = TextBox1.Text
            TextBox1.Text = ""
        End If
        If TextBox1.Text <> "" And TextBox2.Text <> "" Then
            TextBox2.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
            TextBox1.Text = ""
        End If
        TextBox3.Text = "+"
    End Sub
    Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
        Button18.PerformClick()
        If TextBox1.Text <> "" And TextBox2.Text = "" Then
            TextBox2.Text = TextBox1.Text
            TextBox1.Text = ""
        End If
        If TextBox1.Text <> "" And TextBox2.Text <> "" Then
            TextBox2.Text = Val(TextBox2.Text) - Val(TextBox1.Text)
            TextBox1.Text = ""
        End If
        TextBox3.Text = "-"
    End Sub
    Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
        TextBox1.Text = "" : TextBox2.Text = "" : TextBox3.Text = "" : TextBox4.Text = ""
    End Sub
    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
        TextBox4.Text = TextBox2.Text
        If TextBox2.Text = "" Then : Else
            If TextBox2.Text - Int(TextBox2.Text) <> 0 Then
                TextBox4.Text = Format(Val(TextBox4.Text), "#,##0.0000")
            Else
                TextBox4.Text = Format(Val(TextBox4.Text), "#,##0")
            End If
        End If
        If Val(TextBox2.Text) > 9.99973000350998E+85 Then
            MsgBox("EFFORT错误！结果过大请点击AC重新启动!!!")
        End If
    End Sub
    Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
        If TextBox1.Text <> "" And TextBox2.Text <> "" Then
            If TextBox3.Text = "X" Then
                TextBox2.Text = Val(TextBox1.Text) * Val(TextBox2.Text) : TextBox1.Text = ""
            End If
            If TextBox3.Text = "/" Then
                TextBox2.Text = Val(TextBox2.Text) / Val(TextBox1.Text) : TextBox1.Text = ""
            End If
            If TextBox3.Text = "+" Then
                TextBox2.Text = Val(TextBox1.Text) + Val(TextBox2.Text) : TextBox1.Text = ""
            End If
            If TextBox3.Text = "-" Then
                TextBox2.Text = Val(TextBox2.Text) - Val(TextBox1.Text) : TextBox1.Text = ""
            End If
        Else
        End If
    End Sub

End Class
