作业帮 > 数学 > 作业

计算器中按键的用法举例说明一下.不太懂

来源:学生作业帮 编辑:百度作业网作业帮 分类:数学作业 时间:2024/08/08 20:50:32
计算器中按键的用法
举例说明一下.不太懂
计算器中按键的用法举例说明一下.不太懂
什么按键啊我编了一个把代码给你吧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 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_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.Enabled = 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 SubPrivate 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 txtScreen.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 "无数字,无法计算"ElseIf 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.TexttxtScreen2.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 = "^" ThencmdSpr.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 & txtScreen & 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.Enabled = 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 = 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.Text = 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 = 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 = fs = Log(s)txtScreen.Text = stxtScreen2.Text = 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 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 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.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.Enabled = 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 = 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 = "" ThenMsgBox "无数字,无法计算"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.Enabled = 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.Enabled = 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 "无数字,无法计算"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.Enabled = 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 = "-" & txtScreen & 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_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 IfEnd 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中无数据"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 = ""mnuA.Enabled = FalsemnuB.Enabled = FalsemnuC.Enabled = FalsemnuD.Enabled = FalseEnd SubPrivate Sub mnuZT_Click()txtScreen.SelText = Clipboard.GetText(vbCFText)End Sub