欢迎来到天天文库
浏览记录
ID:44820935
大小:267.93 KB
页数:5页
时间:2019-10-30
《编写计算器程序代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、编写计算器程序代码建立14个按钮,按钮的名字都要Command1,设置Index属性,0~9分别对应数字0~9,10为小数点,11为等号,12~14分别对应+、-、*和/。2、输入如下代码:DimNum1,Num2AsSingleDimStrNum1,StrNum2AsStringDimFirstNumAsBooleanDimPointFlagAsBooleanDimRunsignAsIntegerDimSignFlagAsBooleanPrivateSubCommand1_Click(IndexAsInteger)Selec
2、tCaseIndexCase0To9IfFirstNumThenStrNum1=Str(Index)FirstNum=FalseElseStrNum1=LTrim(StrNum1)+LTrim(Str(Index))EndIfText1.Text=Val(StrNum1)Case10IfNotPointFlagThenIfFirstNumThenStrNum1="0."FirstNum=FalseElseStrNum1=LTrim(StrNum1)+LTrim(".")EndIfElseExitSubEndIfPointFla
3、g=TrueText1.Text=Val(StrNum1)Case12To15FirstNum=TruePointFlag=FalseIfSignFlagThenCallRunElseSignFlag=TrueStrNum2=StrNum1StrNum1=""EndIfRunsign=Index-11Case11OnErrorResumeNextIfNotSignFlagThenText1.Text=StrNum1equal=Val(StrNum1)FirstNum=TruePointFlag=FalseElseCallRun
4、SignFlag=FalseEndIfCaseElseCallClearDataEndSelectEndSubPrivateSubForm_Load()IfApp.PrevInstanceThenMsgBox"请不要多次运行此程序,谢谢!",vbAbortRetryIgnore:UnloadMeNum1=0Num2=0StrNum1=""StrNum2=""FirstNum=TruePointFlag=FalseRunsign=0SignFlag=FalseEndSubSubRun()OnErrorResumeNextDime
5、qualAsSingleDimequal2AsDoubleNum1=Val(StrNum2)Num2=Val(StrNum1)SelectCaseRunsignCase1equal=Num1+Num2IfNum1>=65536OrNum2>=65536Orequal>=65536Thenequal=0equal2=Num1+Num2EndIfCase2equal=Num1-Num2IfNum1>=65536OrNum2>=65536Orequal>=65536Thenequal=0equal2=Num1-Num2EndIfCa
6、se3equal=Num1*Num2IfNum1>=65536OrNum2>=65536Orequal>=65536Thenequal=0equal2=Num1*Num2EndIfCase4equal=Num1/Num2IfNum1>=65536OrNum2>=65536Orequal>=65536Thenequal=0equal2=Num1/Num2EndIfEndSelectIfequal=0Thena=equal2Elsea=equalStrNum2=Str(a)StrNum1=StrNum2Text1.Text=Val
7、(StrNum2)EndSubSubClearData()Num1=0Num2=0StrNum1=""StrNum2=""FirstNum=TruePointFlag=FalseRunsign=0SignFlag=FalseText1.Text=0EndSub
此文档下载收益归作者所有