计算器VB代码_第1页
计算器VB代码_第2页
计算器VB代码_第3页
计算器VB代码_第4页
计算器VB代码_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 <> 0 Thenf = txtScreen.Texts = fs = Abs(s)txtScreen.Text = stxtScreen2.Text = sEnd IfEnd SubPrivate Sub

2、 cmdAtn_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 = ""f = 0s = 0End SubPrivate Sub cmdClear_

3、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.Enable

4、d = TruecmdTan.Enabled = Truecmdspr2.Enabled = TruecmdGHH.Enabled = TrueEnd SubPrivate Sub cmdCos_Click()If txtScreen.Text = "" ThenMsgBox "无数字,无法计算"ElseIf txtScreen.Text <> "" Thenf = txtScreen.Texts = fs = Cos(s)txtScreen.Text = stxtScreen2.Text = sEnd IfEnd Sub

5、Private Sub cmdDigit_Click(Index As Integer)txtScreen.Text = txtScreen.Text & cmdDigit(Index).Captions = txtScreen.TextEnd SubPrivate Sub cmdDivide_Click(Index As Integer)If p = "" ThentxtScreen.Text = ""p = "/"f = ss = 0End IfEnd SubPrivate Sub cmdds_Click()If txtS

6、creen.Text = "" ThenMsgBox "无数字,无法计算"ElseIf txtScreen.Text <> 0 Thenf = txtScreen.Texts = fs = 1 / ftxtScreen.Text = stxtScreen2.Text = sElseMsgBox "分子不能为零。"End IfEnd SubPrivate Sub cmden_Click()If txtScreen.Text = "" ThenMsgBox "无数字,无法计算"ElseI

7、f txtScreen.Text <> "" Thenf = txtScreen.Texts = fs = Exp(s)txtScreen.Text = stxtScreen2.Text = sEnd IfEnd SubPrivate Sub cmdEnd_Click()Unload Form1Unload Calc1End SubPrivate Sub cmdEqual_Click(Index As Integer)On Err GoTo e1If p = "" Thens = stxtScreen.Text = txtScreen.Tex

8、ttxtScreen2.Text = txtScreen.TextElseIf p = "+" Thens = f + stxtScreen.Text = stxtScreen2.Text = ss = sElseIf p = "-" Thens = f - stxtScreen.Text = stxtScreen2.Text = ss = sElseIf p = "*" Thens = f * stxtScreen.Text = stxtScreen2.Text = ss = sElseIf p = "" The

9、ncmdSpr.Enabled = TruecmdXmY.Enabled = TruecmdCos.Enabled = TruecmdSin.Enabled = TruecmdMi.Enabled = TruecmdAbs.Enabled = Truecmdds.Enabled = TruecmdAtn.Enabled = TruecmdeN.Enabled = TruecmdLog.Enabled = TruecmdTan.Enabled = Truecmdspr2.Enabled = Trues = f sIf s < 0 ThentxtScreen.Text = 0 & t

10、xtScreen & TexttxtScreen2.Text = 0 & txtScreen & TextEnd IftxtScreen.Text = stxtScreen2.Text = ss = sElseIf p = "spr" ThencmdSpr.Enabled = TruecmdXmY.Enabled = TruecmdCos.Enabled = TruecmdSin.Enabled = TruecmdMi.Enabled = TruecmdAbs.Enabled = Truecmdds.Enabled = TruecmdAtn.Enab

11、led = TruecmdeN.Enabled = TruecmdLog.Enabled = TruecmdTan.Enabled = Trues = f (1 / s)txtScreen.Text = stxtScreen2.Text = ss = sElseIf p = "spr" And s = 0 Thens = 1If s < 0 ThentxtScreen.Text = 0 & txtScreen & TexttxtScreen2.Text = 0 & txtScreen & TextEnd IftxtScreen.Text

12、 = stxtScreen2.Text = ss = sElseIf p = "/" And s <> 0 Thens = f / sIf s < 0 ThentxtScreen.Text = 0 & txtScreen & TexttxtScreen2.Text = 0 & txtScreen & TextEnd IftxtScreen.Text = stxtScreen2.Text = ss = sElseMsgBox "除数不能为零"End IfIf s < 0 ThentxtScreen.T

13、ext = 0 & txtScreen & TexttxtScreen2.Text = 0 & txtScreen & TextEnd IfExit Sube1:If Err = 6 ThenMsgBox "数值溢出!"End IfEnd SubPrivate Sub cmdGHH_Click()s = s 2txtGH.Text = sIf txtGH.Text <> "" And txtGH.Text <> "0" ThencmdGHH.Enabled = FalseElse

14、If txtGH.Text = "" And txtGH.Text = "0" ThencmdGHH.Enabled = TrueEnd IfEnd SubPrivate Sub cmdLog_Click()If txtScreen.Text = "" ThenMsgBox "无数字,无法计算"ElseIf txtScreen.Text <> "" Thenf = txtScreen.Texts = fs = Log(s)txtScreen.Text = stxtScreen2.Te

15、xt = sEnd IfEnd SubPrivate Sub cmdMi_Click()On Err GoTo r1If txtScreen.Text = "" ThenMsgBox "无数字,无法计算"ElseIf txtScreen.Text <> "" Thenf = txtScreen.Texts = fs = s 2txtScreen.Text = stxtScreen2.Text = sEnd IfExit Subr1:If Err = 6 ThenMsgBox "数值溢出!"End IfE

16、nd 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 SubPrivate Sub cmdPi_Click()s = fEnd

17、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.Text = txtScreen.Text & "."End IfEnd SubPr

18、ivate 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

19、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 = False

20、Elsed = txtScreen.TextmnuD.Enabled = TrueEnd IfEnd SubPrivate Sub cmdSin_Click()If txtScreen.Text <> "" Thenf = txtScreen.Texts = fs = Sin(s)txtScreen.Text = stxtScreen2.Text = sElseMsgBox "请输入数字"End IfEnd SubPrivate Sub cmdSpr_Click()If txtScreen.Text = "" ThenMs

21、gBox "无数字,无法计算"ElseIf 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.Ena

22、bled = FalsecmdAbs.Enabled = Falsecmdds.Enabled = FalsecmdAtn.Enabled = FalsecmdeN.Enabled = FalsecmdLog.Enabled = FalsecmdTan.Enabled = FalseIf txtScreen.Text <> "" ThentxtScreen.Text = ""p = "spr"f = ss = 0ElsecmdSpr.Enabled = TruecmdXmY.Enabled = TruecmdCos.Ena

23、bled = TruecmdSin.Enabled = TruecmdMi.Enabled = TruecmdAbs.Enabled = Truecmdds.Enabled = TruecmdAtn.Enabled = TruecmdeN.Enabled = TruecmdLog.Enabled = TruecmdTan.Enabled = TrueMsgBox "请输入数字!"End IfEnd SubPrivate Sub cmdTan_Click()If txtScreen.Text = "" ThenMsgBox "无数字,无法计算&q

24、uot;ElseIf txtScreen.Text <> "" Thenf = txtScreen.Texts = fs = Tan(s)txtScreen.Text = stxtScreen2.Text = sEnd IfEnd SubPrivate Sub cmdXmY_Click()cmdSpr.Enabled = FalsecmdCos.Enabled = FalsecmdSin.Enabled = FalsecmdMi.Enabled = FalsecmdAbs.Enabled = Falsecmdds.Enabled = FalsecmdAtn.En

25、abled = FalsecmdeN.Enabled = FalsecmdLog.Enabled = FalsecmdTan.Enabled = Falsecmdspr2.Enabled = Falsep = ""txtScreen.Text = ""f = ss = 0End SubPrivate Sub Command1_Click()If txtScreen.Text = "" ThentxtScreen.Text = "-"ElsetxtScreen.Text = "-" & t

26、xtScreen & TextEnd IfEnd SubPrivate Sub Form_Load()mnuA.Enabled = FalsemnuB.Enabled = FalsemnuC.Enabled = FalsemnuD.Enabled = FalseEnd SubPrivate Sub mnuA_Click()If a <> "" ThentxtScreen.Text = as = a Or f = aElseMsgBox "数据导入时出错!存储器A中无数据"End IfEnd SubPrivate Sub mnuARR_

27、Click()calcAbout.ShowEnd SubPrivate Sub mnuB_Click()If b <> "" ThentxtScreen.Text = bs = b Or f = aElseMsgBox "数据导入时出错!存储器B中无数据"End IfEnd SubPrivate Sub mnuC_Click()If c <> "" ThentxtScreen.Text = cs = c Or f = cElseMsgBox "数据导入时出错!存储器C中无数据"End IfE

28、nd SubPrivate Sub mnuCopy_Click()If Clipboard.GetFormat(vbCFText) = False ThenClipboard.SetText txtScreen.SelText, vbCFTextmnuZT.Enabled = TrueElsemnuZT.Enabled = FalseEnd IfEnd SubPrivate Sub mnuD_Click()If d <> "" ThentxtScreen.Text = ds = d Or f = dElseMsgBox "数据导入时出错!存储器D中无数

29、据"End IfEnd SubPrivate Sub mnuKX_Click()mnuPT.Checked = FalsemnuKX.Checked = TrueUnload Form1Calc1.ShowEnd SubPrivate Sub mnuPT_Click()mnuKX.Checked = FalsemnuPT.Checked = TrueUnload Calc1Form1.ShowEnd SubPrivate Sub mnuSC_Click()a = ""b = ""c = ""d = ""m

30、nuA.Enabled = FalsemnuB.Enabled = FalsemnuC.Enabled = FalsemnuD.Enabled = FalseEnd SubPrivate Sub mnuZT_Click()txtScreen.SelText = Clipboard.GetText(vbCFText)End SubPublic Class frmcomputer Dim strA As String = "" Dim strB As String = " " Dim c As String = "+" Dim n As

31、String = " " Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtexpr.TextChanged strB = txtexpr.Text End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click strB = Button1.Text

32、txtexpr.Text = txtexpr.Text + strB strB = txtexpr.Text End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click strB = Button2.Text txtexpr.Text = txtexpr.Text + strB strB = txtexpr.Text End Sub Private Sub Button3_Click(ByVal sender As Syst

33、em.Object, ByVal e As System.EventArgs) Handles Button3.Click strB = Button3.Text txtexpr.Text = txtexpr.Text + strB strB = txtexpr.Text End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click strB = Button4.Text txtexpr.Text = txtexpr.Text

34、 + strB strB = txtexpr.Text End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click strB = Button5.Text txtexpr.Text = txtexpr.Text + strB strB = txtexpr.Text End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As Syste

35、m.EventArgs) Handles Button6.Click strB = Button6.Text txtexpr.Text = txtexpr.Text + strB strB = txtexpr.Text End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click strB = Button7.Text txtexpr.Text = txtexpr.Text + strB strB = txtexpr.Text

36、 End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click strB = Button8.Text txtexpr.Text = txtexpr.Text + strB strB = txtexpr.Text End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button

37、9.Click strB = Button9.Text txtexpr.Text = txtexpr.Text + strB strB = txtexpr.Text End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click strB = Button10.Text txtexpr.Text = txtexpr.Text + strB strB = txtexpr.Text End Sub Private Sub But

38、ton12and_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click, Button14.Click, Button13.Click, Button15.Click, Button11.Click strA = strB Select Case sender.TabIndex Case 11 c = "+" txtexpr.Text = " " Case 13 If txtexpr.Text = "" Then

39、 c = "-" Else c = "-" txtexpr.Text = "" End If Case 12 c = "*" txtexpr.Text = "" Case 15 c = "%" txtexpr.Text = CSng(strA) / 100 Case 11 c = "/" If txtexpr.Text = "" Then MsgBox("要有数字输入", 0, "警告") Els

40、eIf strB = "0" Then MsgBox("除数不能为0") Else : txtexpr.Text = " " End If End Select End Sub Private Sub button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click strA = 0 strB = 0 txtexpr.Text = "" End Sub Private Sub butto

41、n17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click If c = "+" Then txtexpr.Text = Val(strA) + Val(strB) strB = txtexpr.Text ElseIf c = "-" Then txtexpr.Text = Val(strA) - Val(strB) strB = txtexpr.Text ElseIf c = "*" Then txtexpr

42、.Text = Val(strA) * Val(strB) strB = txtexpr.Text ElseIf c = "/" Then txtexpr.Text = Val(strA) / Val(strB) strB = txtexpr.Text End If End Sub Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click strA = strB If txtexpr.Text = "&q

43、uot; Then txtexpr.Text = "请输入一个数值" Else txtexpr.Text = Math.Sqrt(txtexpr.Text) strB = txtexpr.Text End If End Sub Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click strA = strB If txtexpr.Text = "" Then MsgBox("请输入一个数值", 0, "警告") Else txtexpr.Text = Math.Pow(txtexpr.Text, 2) strB = txtexpr.Text End If End Sub Private Sub Button11_Click(ByVal sender As System.Object, ByVal

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论