1、Public p As StringPublic f As DoublePublic s As DoubleDim XDim aDim bDim cDim dPrivate Sub cmdAbs_Click()If txtScreen.Text = “ ThenMsgBox “无数字,无法计算“ElseIf txtScreen.Text “ Thenf = txtScreen.Texts = fs = Atn(s)txtScreen.Text = stxtScreen2.Text = sEnd IfEnd SubPrivate Sub cmdClean_Click()txtScreen = “
2、f = 0s = 0End SubPrivate Sub cmdClear_Click()txtScreen.Text = “f = 0s = 0txtScreen2.Text = “txtGH.Text = “cmdSpr.Enabled = TruecmdXmY.Enabled = TruecmdCos.Enabled = TruecmdSin.Enabled = TruecmdMi.Enabled = TruecmdAbs.Enabled = Truecmdds.Enabled = TruecmdAtn.Enabled = TruecmdeN.Enabled = TruecmdLog.E
3、nabled = TruecmdTan.Enabled = Truecmdspr2.Enabled = TruecmdGHH.Enabled = TrueEnd SubPrivate Sub cmdCos_Click()If txtScreen.Text = “ ThenMsgBox “无数字,无法计算“ElseIf txtScreen.Text 0 Thenf = txtScreen.Texts = fs = 1 / ftxtScreen.Text = stxtScreen2.Text = sElseMsgBox “分子不能为零。“End IfEnd SubPrivate Sub cmden
4、_Click()If txtScreen.Text = “ ThenMsgBox “无数字,无法计算“ElseIf txtScreen.Text “0“ ThencmdGHH.Enabled = FalseElseIf txtGH.Text = “ And txtGH.Text = “0“ ThencmdGHH.Enabled = TrueEnd IfEnd SubPrivate Sub cmdLog_Click()If txtScreen.Text = “ ThenMsgBox “无数字,无法计算“ElseIf txtScreen.Text “ Thenf = txtScreen.Texts
5、 = fs = s 2txtScreen.Text = stxtScreen2.Text = sEnd IfExit Subr1:If Err = 6 ThenMsgBox “数值溢出!“End IfEnd SubPrivate Sub cmdMinus_Click()If p = “ ThentxtScreen.Text = “p = “-“f = ss = 0End IfEnd SubPrivate Sub cmdMutiply_Click(Index As Integer)If p = “ ThentxtScreen.Text = “p = “*“f = ss = 0End IfEnd
6、SubPrivate Sub cmdPi_Click()txtScreen.Text = “3.1415926535897932384626433832795“f = 3.14159265358979s = fEnd SubPrivate Sub cmdPlus_Click()If p = “ ThentxtScreen.Text = “p = “+“f = ss = 0End IfEnd SubPrivate Sub cmdPoint_Click(Index As Integer)If txtScreen.Text = “ ThentxtScreen = “0.“ElsetxtScreen.
7、Text = txtScreen.Text & “.“End IfEnd SubPrivate Sub cmdSave1_Click()If txtScreen.Text = “ ThenMsgBox “请输入数字。“mnuA.Enabled = FalseElsea = txtScreen.TextmnuA.Enabled = TrueEnd IfEnd SubPrivate Sub cmdSave2_Click()If txtScreen.Text = “ ThenMsgBox “请输入数字。“mnuB.Enabled = FalseElseb = txtScreen.TextmnuB.E
8、nabled = TrueEnd IfEnd SubPrivate Sub cmdSave3_Click()If txtScreen.Text = “ ThenMsgBox “请输入数字。“mnuC.Enabled = FalseElsec = txtScreen.TextmnuC.Enabled = TrueEnd IfEnd SubPrivate Sub cmdSave4_Click()If txtScreen.Text = “ ThenMsgBox “请输入数字。“mnuD.Enabled = FalseElsed = txtScreen.TextmnuD.Enabled = TrueE
9、nd IfEnd SubPrivate Sub cmdSin_Click()If txtScreen.Text = 0 Thenf = txtScreen.Texts = fs = s (1 / 2)txtScreen.Text = stxtScreen2.Text = sElseMsgBox “底数不能小于零。“End IfEnd SubPrivate Sub cmdspr2_Click()cmdSpr.Enabled = FalsecmdXmY.Enabled = FalsecmdCos.Enabled = FalsecmdSin.Enabled = FalsecmdMi.Enabled
10、= FalsecmdAbs.Enabled = Falsecmdds.Enabled = FalsecmdAtn.Enabled = FalsecmdeN.Enabled = FalsecmdLog.Enabled = FalsecmdTan.Enabled = FalseIf txtScreen.Text “ Thenf = txtScreen.Texts = fs = Tan(s)txtScreen.Text = stxtScreen2.Text = sEnd IfEnd SubPrivate Sub cmdXmY_Click()cmdSpr.Enabled = FalsecmdCos.E
11、nabled = FalsecmdSin.Enabled = FalsecmdMi.Enabled = FalsecmdAbs.Enabled = Falsecmdds.Enabled = FalsecmdAtn.Enabled = FalsecmdeN.Enabled = FalsecmdLog.Enabled = FalsecmdTan.Enabled = Falsecmdspr2.Enabled = Falsep = “txtScreen.Text = “f = ss = 0End SubPrivate Sub Command1_Click()If txtScreen.Text = “
12、ThentxtScreen.Text = “-“ElsetxtScreen.Text = “-“ & txtScreen & TextEnd IfEnd SubPrivate Sub Form_Load()mnuA.Enabled = FalsemnuB.Enabled = FalsemnuC.Enabled = FalsemnuD.Enabled = FalseEnd SubPrivate Sub mnuA_Click()If a “ ThentxtScreen.Text = bs = b Or f = aElseMsgBox “数据导入时出错!存储器 B 中无数据“End IfEnd Su
13、bPrivate Sub mnuC_Click()If c “ ThentxtScreen.Text = ds = d Or f = dElseMsgBox “数据导入时出错!存储器 D 中无数据“End IfEnd SubPrivate Sub mnuKX_Click()mnuPT.Checked = FalsemnuKX.Checked = TrueUnload Form1Calc1.ShowEnd SubPrivate Sub mnuPT_Click()mnuKX.Checked = FalsemnuPT.Checked = TrueUnload Calc1Form1.ShowEnd S
14、ubPrivate Sub mnuSC_Click()a = “b = “c = “d = “mnuA.Enabled = FalsemnuB.Enabled = FalsemnuC.Enabled = FalsemnuD.Enabled = FalseEnd SubPrivate Sub mnuZT_Click()txtScreen.SelText = Clipboard.GetText(vbCFText)End SubPublic Class frmcomputerDim strA As String = “Dim strB As String = “ “Dim c As String =
15、 “+“Dim n As String = “ “Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtexpr.TextChangedstrB = txtexpr.TextEnd SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickstrB = Button1.Texttxt
16、expr.Text = txtexpr.Text + strBstrB = txtexpr.TextEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickstrB = Button2.Texttxtexpr.Text = txtexpr.Text + strBstrB = txtexpr.TextEnd SubPrivate Sub Button3_Click(ByVal sender As System.Object,
17、ByVal e As System.EventArgs) Handles Button3.ClickstrB = Button3.Texttxtexpr.Text = txtexpr.Text + strBstrB = txtexpr.TextEnd SubPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.ClickstrB = Button4.Texttxtexpr.Text = txtexpr.Text + strBstrB = txte
18、xpr.TextEnd SubPrivate Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.ClickstrB = Button5.Texttxtexpr.Text = txtexpr.Text + strBstrB = txtexpr.TextEnd SubPrivate Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
19、n6.ClickstrB = Button6.Texttxtexpr.Text = txtexpr.Text + strBstrB = txtexpr.TextEnd SubPrivate Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.ClickstrB = Button7.Texttxtexpr.Text = txtexpr.Text + strBstrB = txtexpr.TextEnd SubPrivate Sub Button8_Click(B
20、yVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.ClickstrB = Button8.Texttxtexpr.Text = txtexpr.Text + strBstrB = txtexpr.TextEnd SubPrivate Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.ClickstrB = Button9.Texttxtexpr.Text =
21、txtexpr.Text + strBstrB = txtexpr.TextEnd SubPrivate Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.ClickstrB = Button10.Texttxtexpr.Text = txtexpr.Text + strBstrB = txtexpr.TextEnd SubPrivate Sub Button12and_Click(ByVal sender As System.Object, ByVal
22、 e As System.EventArgs) Handles Button12.Click, Button14.Click, Button13.Click, Button15.Click, Button11.ClickstrA = strBSelect Case sender.TabIndexCase 11c = “+“txtexpr.Text = “ “Case 13If txtexpr.Text = “ Thenc = “-“Elsec = “-“txtexpr.Text = “End IfCase 12c = “*“txtexpr.Text = “Case 15c = “%“txtex
23、pr.Text = CSng(strA) / 100Case 11c = “/“If txtexpr.Text = “ ThenMsgBox(“要有数字输入“, 0, “警告“)ElseIf strB = “0“ ThenMsgBox(“除数不能为 0“)Else : txtexpr.Text = “ “End IfEnd SelectEnd SubPrivate Sub button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.ClickstrA = 0strB =
24、0txtexpr.Text = “End SubPrivate Sub button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.ClickIf c = “+“ Thentxtexpr.Text = Val(strA) + Val(strB)strB = txtexpr.TextElseIf c = “-“ Thentxtexpr.Text = Val(strA) - Val(strB)strB = txtexpr.TextElseIf c = “*“ Thentxte
25、xpr.Text = Val(strA) * Val(strB)strB = txtexpr.TextElseIf c = “/“ Thentxtexpr.Text = Val(strA) / Val(strB)strB = txtexpr.TextEnd IfEnd SubPrivate Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.ClickstrA = strBIf txtexpr.Text = “ Thentxtexpr.Text = “请输
26、入一个数值“Elsetxtexpr.Text = Math.Sqrt(txtexpr.Text)strB = txtexpr.TextEnd IfEnd SubPrivate Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.ClickstrA = strBIf txtexpr.Text = “ ThenMsgBox(“请输入一个数值“, 0, “警告“)Elsetxtexpr.Text = Math.Pow(txtexpr.Text, 2)strB =
27、 txtexpr.TextEnd IfEnd SubPrivate Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.ClickstrA = strBIf txtexpr.Text = “ ThenMsgBox(“要有数字输入“, 0, “警告“)End IfIf strB = “0“ ThenMsgBox(“除数不为零“, 0, “警告“)Else : txtexpr.Text = “End IfEnd SubPrivate Sub Button19_
28、Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Clicktxtexpr.Text = txtexpr.Text & “.“End SubPrivate Sub backspace_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Button12.KeyPressIf e.KeyChar = Chr(8) ThenIf Len(txtexpr.
29、Text) Len(“) Thentxtexpr.Text = Strings.Left(txtexpr.Text, Len(txtexpr.Text) - 1)Elsetxtexpr.Text = “End IfEnd IfEnd SubPrivate Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.ClickIf Len(txtexpr.Text) Len(“) Thentxtexpr.Text = Strings.Left(txtexpr.Tex
30、t, Len(txtexpr.Text) - 1)Elsetxtexpr.Text = “End IfEnd SubPrivate Sub FrmComputer_keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPressIf Not (e.KeyChar Chr(47) And e.KeyChar Chr(58) ThenMsgBox(“请输入数字“, 0, “警告“)Else : txtexpr.Text = txtexpr.TextEnd IfEnd SubPrivate Sub frmcomputer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadEnd SubEnd Class