資源描述:
《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=固定(努姆)然后整數(shù)標簽=民“?!盓lseIfLeft(num,1)=“”。然后第一個字符為小數(shù)點=“0”&Numla
8、bel1ElseIfLeft(num,2)=“”。然