欢迎来到天天文库
浏览记录
ID:36003259
大小:18.72 KB
页数:15页
时间:2019-04-29
《vb实例代码-计算器(vb instance code calculator)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、vb实例代码-计算器(VBinstancecodecalculator)First,thefollowingcontrolsneedtobecreated:Tags:Label1Commandbutton:NameCaptionvalueCback..CclearCECstartCCsinSinCcosCosCsqrtSqrtCsign+/-CpointCpointCequal=Controlarray:(commandbutton)Calcu(1)+Calcu(2)-Calcu(3)*Calcu(4)/Cnum(0)0Cnum(1)1...Cnum(9)9
2、Thenwritethesourcecodeinthecodewindow:OptionExplicitDimNum1,Num2AsDoubleDimPointInAsBooleanDimInputingAsBooleanDimOperation1AsIntegerPrivateSubCalcu_Click(IAsInteger)IfInputing=FalseThen'hasnotenterednewdataafterthelastoperationwassubmittedOperation1=I'operatorresetNum1=Label1'assi
3、gnsthedatainthedisplaycolumntothefirstoperandExitSubEndIfInputing=False'setsthecurrentstatetoanoninputdataphaseIfNum10Then<>'noncalculatedforthefirsttimeNum2=Label1'displaysthedatainthecolumntosecondoperandsCalculate(Operation1)'calculatesthepreviousoperationanddisplaystheresultEls
4、e'firstcomputationNum1=Label1'assignsthedatainthedisplaycolumntothefirstoperandEndIfOperation1=I'SubmitoperatorEndSubPrivateSubCback_Click()DimTheLenAsIntegerTheLen=Len(Label1)IfTheLen>2ThenIfRight(Label1,1)="."ThenLabel1=Left(Label1,TheLen-2)&"ElseLabel1=Left(Label1,TheLen-1)EndIf
5、ElseCclear_ClickEndIfEndSubPrivateSubCclear_Click()Label1="0.""Num2=0PointIn=FalseEndSubPrivateSubCcos_Click()Calculate(6)Inputing=FalseEndSubPrivateSubCequal_Click()IfInputingThen'ifyoujustentereddata'OrOperation1>0ThenNum2=Label1'displaysthedatainthecolumntosecondoperandsEndIfInp
6、uting=False'setsthecurrentstatetoanoninputdataphaseCalculate(Operation1)'calculatesthesubmittedoperationsanddisplaystheresultsNum1=0Operation1=0EndSubPrivateSubCalculate(OprtAsInteger)SelectCaseOprtCase1Num1=Num1+Num2ShowResult(Num1)Case2Num1=Num1-Num2ShowResult(Num1)Case3Num1=Num1
7、*Num2ShowResult(Num1)Case4Num1=Num1/Num2ShowResult(Num1)Case5Num2=Label1Num1=Sin(Num2)ShowResult(Num1)Case6Num2=Label1Num1=Cos(Num2)ShowResult(Num1)Case7num2=label1num1=sqr(num2)显示诊断结果(num1)最后选择端子列兵SubShowResult(Num双)如果num=固定(努姆)然后整数标签=民“。”ElseIfLeft(num,1)=“”。然后第一个字符为小数点=“0”&Numla
8、bel1ElseIfLeft(num,2)=“”。然
此文档下载收益归作者所有