Public Class 計算機 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 計算前_tb.Enabled = False : 計算後_tb.Enabled = False : 計算式_tb.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 : 一_bt.PerformClick() : Case Keys.NumPad2 : 二_bt.PerformClick() : Case Keys.NumPad3 : 三_bt.PerformClick() : Case Keys.NumPad4 : 四_bt.PerformClick() Case Keys.NumPad5 : 五_bt.PerformClick() : Case Keys.NumPad6 : 六_bt.PerformClick() : Case Keys.NumPad7 : 七_bt.PerformClick() : Case Keys.NumPad8 : 八_bt.PerformClick() Case Keys.NumPad9 : 九_bt.PerformClick() : Case Keys.NumPad0 : 零_bt.PerformClick() : Case Keys.Decimal : 小數點_bt.PerformClick() : Case Keys.D1 : 一_bt.PerformClick() Case Keys.D2 : 二_bt.PerformClick() : Case Keys.D3 : 三_bt.PerformClick() : Case Keys.D4 : 四_bt.PerformClick() : Case Keys.D5 : 五_bt.PerformClick() Case Keys.D6 : 六_bt.PerformClick() : Case Keys.D7 : 七_bt.PerformClick() : Case Keys.D8 : 八_bt.PerformClick() : Case Keys.D9 : 九_bt.PerformClick() Case Keys.D0 : 零_bt.PerformClick() : Case Keys.OemPeriod : 小數點_bt.PerformClick() : Case Keys.Delete : 消除_bt.PerformClick() : Case Keys.Multiply : 乘_bt.PerformClick() Case Keys.Subtract : 減_bt.PerformClick() : Case Keys.OemMinus : 減_bt.PerformClick() : Case Keys.Add : 加_bt.PerformClick() : Case Keys.Oemplus : 加_bt.PerformClick() Case Keys.Oem2 : 除_bt.PerformClick() : Case Keys.Divide : 除_bt.PerformClick() End Select End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 一_bt.Click If 計算前_tb.Text <> "" Then 計算前_tb.Text = 計算前_tb.Text & 1 Else 計算前_tb.Text = 1 End If End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles 二_bt.Click If 計算前_tb.Text <> "" Then 計算前_tb.Text = 計算前_tb.Text & 2 Else 計算前_tb.Text = 2 End If End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles 三_bt.Click If 計算前_tb.Text <> "" Then 計算前_tb.Text = 計算前_tb.Text & 3 Else 計算前_tb.Text = 3 End If End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles 四_bt.Click If 計算前_tb.Text <> "" Then 計算前_tb.Text = 計算前_tb.Text & 4 Else 計算前_tb.Text = 4 End If End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles 五_bt.Click If 計算前_tb.Text <> "" Then 計算前_tb.Text = 計算前_tb.Text & 5 Else 計算前_tb.Text = 5 End If End Sub Private Sub Button6_Click(sender As Object, e As EventArgs) Handles 六_bt.Click If 計算前_tb.Text <> "" Then 計算前_tb.Text = 計算前_tb.Text & 6 Else 計算前_tb.Text = 6 End If End Sub Private Sub Button7_Click(sender As Object, e As EventArgs) Handles 七_bt.Click If 計算前_tb.Text <> "" Then 計算前_tb.Text = 計算前_tb.Text & 7 Else 計算前_tb.Text = 7 End If End Sub Private Sub Button8_Click(sender As Object, e As EventArgs) Handles 八_bt.Click If 計算前_tb.Text <> "" Then 計算前_tb.Text = 計算前_tb.Text & 8 Else 計算前_tb.Text = 8 End If End Sub Private Sub Button9_Click(sender As Object, e As EventArgs) Handles 九_bt.Click If 計算前_tb.Text <> "" Then 計算前_tb.Text = 計算前_tb.Text & 9 Else 計算前_tb.Text = 9 End If End Sub Private Sub Button10_Click(sender As Object, e As EventArgs) Handles 零_bt.Click If 計算前_tb.Text <> "" Then 計算前_tb.Text = 計算前_tb.Text & 0 Else 計算前_tb.Text = 0 End If End Sub Private Sub Button12_Click(sender As Object, e As EventArgs) Handles 小數點_bt.Click If 計算前_tb.Text <> "" Then 計算前_tb.Text = 計算前_tb.Text & "." Else 計算前_tb.Text = "0." End If End Sub '----------------------------數字鍵盤--------------------------------------------------------------------------------------------------------------- Private Sub Button11_Click(sender As Object, e As EventArgs) Handles 消除_bt.Click Dim SS As Integer If 計算前_tb.Text <> "" Then 計算前_tb.Text = Int(Val(計算前_tb.Text) / 10) ElseIf 計算前_tb.Text = "" And 計算後_tb.Text <> "" Then SS = Len(計算後_tb.Text) 計算後_tb.Text = Strings.Left(計算後_tb.Text, SS - 1) Else 計算前_tb.Text = "" End If End Sub Private Sub Button16_Click(sender As Object, e As EventArgs) Handles 除_bt.Click 等於_bt.PerformClick() If 計算前_tb.Text <> "" And 計算後_tb.Text = "" Then 計算後_tb.Text = 計算前_tb.Text 計算前_tb.Text = "" End If If 計算前_tb.Text <> "" And 計算後_tb.Text <> "" Then 計算後_tb.Text = Val(計算後_tb.Text) / Val(計算前_tb.Text) 計算前_tb.Text = "" End If 計算式_tb.Text = "/" End Sub Private Sub Button15_Click(sender As Object, e As EventArgs) Handles 乘_bt.Click 等於_bt.PerformClick() If 計算前_tb.Text <> "" And 計算後_tb.Text = "" Then 計算後_tb.Text = 計算前_tb.Text 計算前_tb.Text = "" End If If 計算前_tb.Text <> "" And 計算後_tb.Text <> "" Then 計算後_tb.Text = Val(計算前_tb.Text) * Val(計算後_tb.Text) 計算前_tb.Text = "" End If 計算式_tb.Text = "X" End Sub Private Sub Button13_Click(sender As Object, e As EventArgs) Handles 加_bt.Click 等於_bt.PerformClick() If 計算前_tb.Text <> "" And 計算後_tb.Text = "" Then 計算後_tb.Text = 計算前_tb.Text 計算前_tb.Text = "" End If If 計算前_tb.Text <> "" And 計算後_tb.Text <> "" Then 計算後_tb.Text = Val(計算前_tb.Text) + Val(計算後_tb.Text) 計算前_tb.Text = "" End If 計算式_tb.Text = "+" End Sub Private Sub Button14_Click(sender As Object, e As EventArgs) Handles 減_bt.Click 等於_bt.PerformClick() If 計算前_tb.Text <> "" And 計算後_tb.Text = "" Then 計算後_tb.Text = 計算前_tb.Text 計算前_tb.Text = "" End If If 計算前_tb.Text <> "" And 計算後_tb.Text <> "" Then 計算後_tb.Text = Val(計算後_tb.Text) - Val(計算前_tb.Text) 計算前_tb.Text = "" End If 計算式_tb.Text = "-" End Sub Private Sub Button17_Click(sender As Object, e As EventArgs) Handles 清空_bt.Click 計算前_tb.Text = "" : 計算後_tb.Text = "" : 計算式_tb.Text = "" : 答案_tb.Text = "" End Sub Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles 計算後_tb.TextChanged 答案_tb.Text = 計算後_tb.Text If 計算後_tb.Text = "" Then : Else If 計算後_tb.Text - Int(計算後_tb.Text) <> 0 Then 答案_tb.Text = Format(Val(答案_tb.Text), "#,##0.0000") Else 答案_tb.Text = Format(Val(答案_tb.Text), "#,##0") End If End If If Val(計算後_tb.Text) > 9.99973000350998E+85 Then MsgBox("EFFORT错误!结果过大请点击AC重新启动!!!") End If End Sub Private Sub Button18_Click(sender As Object, e As EventArgs) Handles 等於_bt.Click If 計算前_tb.Text <> "" And 計算後_tb.Text <> "" Then If 計算式_tb.Text = "X" Then 計算後_tb.Text = Val(計算前_tb.Text) * Val(計算後_tb.Text) : 計算前_tb.Text = "" End If If 計算式_tb.Text = "/" Then 計算後_tb.Text = Val(計算後_tb.Text) / Val(計算前_tb.Text) : 計算前_tb.Text = "" End If If 計算式_tb.Text = "+" Then 計算後_tb.Text = Val(計算前_tb.Text) + Val(計算後_tb.Text) : 計算前_tb.Text = "" End If If 計算式_tb.Text = "-" Then 計算後_tb.Text = Val(計算後_tb.Text) - Val(計算前_tb.Text) : 計算前_tb.Text = "" End If Else End If End Sub End Class