Public Class 計算機 Private Sub 計算機_Load(sender As Object, e As EventArgs) Handles MyBase.Load 數值2_tb.Enabled = False : 數值1_tb.Enabled = False : 計算式_tb.Enabled = False Me.KeyPreview = True 數值2_tb.Text = "" : 數值1_tb.Text = "" : 計算式_tb.Text = "" : 結果_tb.Text = "" End Sub Private Sub 計算機_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown If 計算機調 = "報價總表" Then If Val(PA30) > 0 Then : 數值2_tb.Text = PA30 : 等於_bt.PerformClick() : Else : PA30 = "" : End If Else : PA30 = "" : End If End Sub Private Sub Form_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown Select Case e.KeyCode Case Keys.NumPad1 : Me.ActiveControl = b1_bt : b1_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.NumPad2 : Me.ActiveControl = b2_bt : b2_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.NumPad3 : Me.ActiveControl = b3_bt : b3_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.NumPad4 : Me.ActiveControl = b4_bt : b4_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.NumPad5 : Me.ActiveControl = b5_bt : b5_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.NumPad6 : Me.ActiveControl = b6_bt : b6_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.NumPad7 : Me.ActiveControl = b7_bt : b7_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.NumPad8 : Me.ActiveControl = b8_bt : b8_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.NumPad9 : Me.ActiveControl = b9_bt : b9_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.NumPad0 : Me.ActiveControl = b0_bt : b0_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.Decimal : Me.ActiveControl = 小數點_bt : 小數點_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.D1 : Me.ActiveControl = b1_bt : b1_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.D2 : Me.ActiveControl = b2_bt : b2_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.D3 : Me.ActiveControl = b3_bt : b3_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.D4 : Me.ActiveControl = b4_bt : b4_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.D5 : Me.ActiveControl = b5_bt : b5_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.D6 : Me.ActiveControl = b6_bt : b6_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.D7 : Me.ActiveControl = b7_bt : b7_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.D8 : Me.ActiveControl = b8_bt : b8_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.D9 : Me.ActiveControl = b9_bt : b9_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.D0 : Me.ActiveControl = b0_bt : b0_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.OemPeriod : Me.ActiveControl = 小數點_bt : 小數點_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.Delete : Me.ActiveControl = 倒退_bt : 倒退_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.Multiply : Me.ActiveControl = 乘_bt : 乘_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.Subtract : Me.ActiveControl = 減_bt : 減_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.OemMinus : Me.ActiveControl = 減_bt : 減_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.Add : Me.ActiveControl = 加_bt : 加_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.Oemplus : Me.ActiveControl = 加_bt : 加_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.Oem2 : Me.ActiveControl = 除_bt : 除_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.Divide : Me.ActiveControl = 除_bt : 除_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.Back : Me.ActiveControl = 倒退_bt : 倒退_bt.PerformClick() : Me.ActiveControl = 等於_bt Case Keys.Return : Me.ActiveControl = 倒退_bt : 倒退_bt.PerformClick() : Me.ActiveControl = 等於_bt End Select End Sub Private Sub B1_bt_Click(sender As Object, e As EventArgs) Handles b1_bt.Click If 數值2_tb.Text <> "" Then : 數值2_tb.Text = 數值2_tb.Text & 1 : Else : 數值2_tb.Text = 1 : End If End Sub Private Sub B2_bt_Click(sender As Object, e As EventArgs) Handles b2_bt.Click If 數值2_tb.Text <> "" Then : 數值2_tb.Text = 數值2_tb.Text & 2 : Else : 數值2_tb.Text = 2 : End If End Sub Private Sub B3_bt_Click(sender As Object, e As EventArgs) Handles b3_bt.Click If 數值2_tb.Text <> "" Then : 數值2_tb.Text = 數值2_tb.Text & 3 : Else : 數值2_tb.Text = 3 : End If End Sub Private Sub B4_bt_Click(sender As Object, e As EventArgs) Handles b4_bt.Click If 數值2_tb.Text <> "" Then : 數值2_tb.Text = 數值2_tb.Text & 4 : Else : 數值2_tb.Text = 4 : End If End Sub Private Sub B5_bt_Click(sender As Object, e As EventArgs) Handles b5_bt.Click If 數值2_tb.Text <> "" Then : 數值2_tb.Text = 數值2_tb.Text & 5 : Else : 數值2_tb.Text = 5 : End If End Sub Private Sub B6_bt_Click(sender As Object, e As EventArgs) Handles b6_bt.Click If 數值2_tb.Text <> "" Then : 數值2_tb.Text = 數值2_tb.Text & 6 : Else : 數值2_tb.Text = 6 : End If End Sub Private Sub B7_bt_Click(sender As Object, e As EventArgs) Handles b7_bt.Click If 數值2_tb.Text <> "" Then : 數值2_tb.Text = 數值2_tb.Text & 7 : Else : 數值2_tb.Text = 7 : End If End Sub Private Sub B8_bt_Click(sender As Object, e As EventArgs) Handles b8_bt.Click If 數值2_tb.Text <> "" Then : 數值2_tb.Text = 數值2_tb.Text & 8 : Else : 數值2_tb.Text = 8 : End If End Sub Private Sub B9_bt_Click(sender As Object, e As EventArgs) Handles b9_bt.Click If 數值2_tb.Text <> "" Then : 數值2_tb.Text = 數值2_tb.Text & 9 : Else : 數值2_tb.Text = 9 : End If End Sub Private Sub B0_bt_Click(sender As Object, e As EventArgs) Handles b0_bt.Click If 數值2_tb.Text <> "" Then : 數值2_tb.Text = 數值2_tb.Text & 0 : Else : 數值2_tb.Text = 0 : End If End Sub Private Sub 小數點_bt_Click(sender As Object, e As EventArgs) Handles 小數點_bt.Click If 數值2_tb.Text <> "" Then : 數值2_tb.Text = 數值2_tb.Text & "." : Else : 數值2_tb.Text = "0." : End If End Sub '----------------------------數字鍵盤--------------------------------------------------------------------------------------------------------------- Private Sub 倒退_bt_Click(sender As Object, e As EventArgs) Handles 倒退_bt.Click Dim SS As Integer If 數值2_tb.Text <> "" Then : 數值2_tb.Text = Int(Val(數值2_tb.Text) / 10) ElseIf 數值2_tb.Text = "" And 數值1_tb.Text <> "" Then : SS = Len(數值1_tb.Text) : 數值1_tb.Text = Strings.Left(數值1_tb.Text, SS - 1) Else : 數值2_tb.Text = "" : End If End Sub Private Sub 除_bt_Click(sender As Object, e As EventArgs) Handles 除_bt.Click 等於_bt.PerformClick() If 數值2_tb.Text <> "" And 數值1_tb.Text = "" Then : 數值1_tb.Text = 數值2_tb.Text : 數值2_tb.Text = "" : End If If 數值2_tb.Text <> "" And 數值1_tb.Text <> "" Then : 數值1_tb.Text = Val(數值1_tb.Text) / Val(數值2_tb.Text) : 數值2_tb.Text = "" : End If 計算式_tb.Text = "/" End Sub Private Sub 乘_bt_Click(sender As Object, e As EventArgs) Handles 乘_bt.Click 等於_bt.PerformClick() If 數值2_tb.Text <> "" And 數值1_tb.Text = "" Then : 數值1_tb.Text = 數值2_tb.Text : 數值2_tb.Text = "" : End If If 數值2_tb.Text <> "" And 數值1_tb.Text <> "" Then : 數值1_tb.Text = Val(數值2_tb.Text) * Val(數值1_tb.Text) : 數值2_tb.Text = "" : End If 計算式_tb.Text = "X" End Sub Private Sub 加_bt_Click(sender As Object, e As EventArgs) Handles 加_bt.Click 等於_bt.PerformClick() If 數值2_tb.Text <> "" And 數值1_tb.Text = "" Then : 數值1_tb.Text = 數值2_tb.Text : 數值2_tb.Text = "" : End If If 數值2_tb.Text <> "" And 數值1_tb.Text <> "" Then : 數值1_tb.Text = Val(數值2_tb.Text) + Val(數值1_tb.Text) : 數值2_tb.Text = "" : End If 計算式_tb.Text = "+" End Sub Private Sub 減_bt_Click(sender As Object, e As EventArgs) Handles 減_bt.Click 等於_bt.PerformClick() If 數值2_tb.Text <> "" And 數值1_tb.Text = "" Then : 數值1_tb.Text = 數值2_tb.Text : 數值2_tb.Text = "" : End If If 數值2_tb.Text <> "" And 數值1_tb.Text <> "" Then : 數值1_tb.Text = Val(數值1_tb.Text) - Val(數值2_tb.Text) : 數值2_tb.Text = "" : End If 計算式_tb.Text = "-" End Sub Private Sub 清除_bt_Click(sender As Object, e As EventArgs) Handles 清除_bt.Click 數值2_tb.Text = "" : 數值1_tb.Text = "" : 計算式_tb.Text = "" : 結果_tb.Text = "" End Sub Private Sub 數值1_tb_TextChanged(sender As Object, e As EventArgs) Handles 數值1_tb.TextChanged 結果_tb.Text = 數值1_tb.Text If 數值1_tb.Text = "" Then : Else If 數值1_tb.Text - Int(數值1_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(數值1_tb.Text) > 9.99973000350998E+85 Then If 系統語言 = "繁體中文" Then : MsgBox("EFFORT錯誤!結果過大,請重新點擊AC來重新啟動!!") Else : MsgBox("kesalahan UPAYA! Hasilnya terlalu besar, silakan klik AC lagi untuk restart!!") : End If : End If End Sub Private Sub 計算結果() If 數值2_tb.Text <> "" And 數值1_tb.Text <> "" Then If 計算式_tb.Text = "X" Then : 數值1_tb.Text = Val(數值2_tb.Text) * Val(數值1_tb.Text) : 數值2_tb.Text = "" : End If If 計算式_tb.Text = "/" Then : 數值1_tb.Text = Val(數值1_tb.Text) / Val(數值2_tb.Text) : 數值2_tb.Text = "" : End If If 計算式_tb.Text = "+" Then : 數值1_tb.Text = Val(數值2_tb.Text) + Val(數值1_tb.Text) : 數值2_tb.Text = "" : End If If 計算式_tb.Text = "-" Then : 數值1_tb.Text = Val(數值1_tb.Text) - Val(數值2_tb.Text) : 數值2_tb.Text = "" : End If ElseIf 數值2_tb.Text <> "" And 數值1_tb.Text = "" Then 結果_tb.Text = 數值2_tb.Text Else : End If End Sub Private Sub 等於_bt_Click(sender As Object, e As EventArgs) Handles 等於_bt.Click 計算結果() End Sub Private Sub 資料寫入_bt_Click(sender As Object, e As EventArgs) Handles 資料寫入_bt.Click 計算結果() If 結果_tb.Text = "" Then If 系統語言 = "繁體中文" Then : MsgBox("沒有資料可以帶入!!") : Else : MsgBox("Tidak ada data untuk dibawa!!") : End If Else PA30 = CInt(結果_tb.Text) : Me.Close() End If End Sub End Class