大學常見的VB編程題_第1頁
大學常見的VB編程題_第2頁
大學常見的VB編程題_第3頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、vb點菜例題PrivateSubcdwh_Click()Form3.ShowEndSubPrivateSubCommand1_Click()IfText3.Text=""ThenMsgBox("請?zhí)顚懽来危?quot;)ExitSubEndIfForm2.ShowEndSubPrivateSubdc_Click()IfText3.Text=""ThenMsgBox("請?zhí)顚懽来危?quot;)ExitSubEndIfForm2.ShowEndSubPrivateSubForm_Load()DimdbAsNewADODB.Connect

2、ionDimdwzAsNewADODB.RecordsetDimstrCnnAsStringstrCnn="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=food.mdb"Setdb=NewADODB.Connection建立連接db.OpenstrCnnSetdwz=NewADODB.Recordset'建立記錄集dwz.CursorLocation=adUseClientdwz.CursorType=adOpenStaticdwz.LockType=adLockOptimisticdwz.Open"select

3、*fromvegetablewherebz=1”,db,adCmdText'查找出表中所列特價IfNotdwz.EOFThendwz.MoveFirstElseListl.AddItem("今日無特價菜!")EndIf2.0歡迎程序PrivateSubCommand1_Click()Text1.FontSize=22Text1.Text="歡迎使用VisualBasic6.0”EndSubPrivateSubCommand2_Click()Text1.Text=""EndSubPrivateSubCommand3_Click()EndE

4、ndSub2.1輸入輸出示例PrivateSubCommand1_Click()Dimr!,l!,s!r=InputBox("請輸入圓的半徑:”+Chr(13)+Chr(10)+_"然后單擊確定","輸入框",1000,1000)'l=2*3.14159*rs=3.14159*r*rText1.Text=rText2.Text=lText3.Text=sEndSubPrivateSubCommand2_Click()EndEndSubPrivateSubForm_Load()Textl=""Text2="&

5、quot;Text3=""EndSub例2.2簡單文本編輯器OptionExplicitDimstrAsStringPrivateSubCmdCopy_Click()str=Text1.SelTextEndSubPrivateSubCmdCut_Click()str=Text1.SelTextText1.SelText=""EndSubPrivateSubCmdDel_Click()Text1=""Text2=""EndSubPrivateSubCmdExit_Click()EndEndSubPrivateSubC

6、mdPas_Click()Text2.SelText=strEndSubPrivateSubForm_Load()Text1=""Text2=""EndSub例2.3用戶登錄OptionExplicitDimn%PrivateSubCommand1_Click()Dima%,b%,c%IfText1=""ThenMsgBox("請輸入用戶名")ExitSubEndIfIfText2=""ThenMsgBox("請輸入密碼")ExitSubEndIfIfLen(Trim(Tex

7、t2)<>6ThenMsgBox("密碼必須為6位!")EndIfIfTrim(Text1)="abc"AndTrim(Text2)="123456”Thena=MsgBox("歡迎使用本系統(tǒng)!","登錄")Elsen=n+1Ifn>=3Thenc=MsgBox("你無權登錄本系統(tǒng)!",_,"密碼錯誤"):Endb=MsgBox("輸入錯誤,再試一次!","密碼錯誤")EndIfEndSubPrivateSu

8、bForm_Load()Text1=""Text2=""EndSubPrivateSubText2_KeyPress(KeyAsciiAsInteger)IfKeyAscii>57OrKeyAscii<48ThenMsgBox”你必須輸入數(shù)字"Text2.SetFocusSendKeys"home+endEndIfEndSub例2.6打印九九乘法表PrivateSubCommand3_Click()Fori=1To9Forj=1Toise=j&""&i&"="

9、&i*jPicturel.PrintTab(j-1)*9+1);se;NextjPicture1.PrintNextiEndSub第五章PrivateSubForm_Click()msg1$="請輸入姓名:"msgtitle$="學生情況登記"msg2$=”請輸入年齡:"msg3$="請輸入性別:"msg4$="請輸入籍貫"studname$=InputBox(msg1$,msgtitle$)studage=InputBox(msg2$,msgtitle$)studsex$=InputBox(ms

10、g3$,msgtitle$)studhome$=InputBox(msg4$,msgtitle$)ClsPrintstudname$;","studsex$;",現(xiàn)年":Printstudage;"歲"","studhome$;"人EndSubPrivateSubForm_Click()c1$=Chr$(13)+Chr$(10)msg1$="輸入雇客名字:"msg2$="輸入后按回車鍵"msg3$=”或單擊確定'按鈕"msg$=msg1$+c1$+

11、msg2$+c1$+msg3$custname$=InputBox(msg$,"InputBoxFunctiondemo","王大力")Printcustname$EndSubPrivateSubForm_Click()msg1$="要繼續(xù)嗎?”msg2$="OperationDialogBox"r=MsgBox(msg1$,34,msg2$)PrintrEndSube68.PrivateSubForm_Load()Display.FontSize=20EndSubPrivateSubDisplay_Change()IfUn

12、derOn.Value=1ThenDisplay.FontUnderline=TrueElseDisplay.FontStrikethru=TrueEndIfEndSubPrivateSubItalicOn_Click()IfItalicOn.Value=1ThenDisplay.FontItalic=TrueElseDisplay.FontItalic=FalseEndIfEndSubPrivateSubUnderon_Click()IfUnderOn.Value=1ThenDisplay.FontUnderline=TrueElseDisplay.FontUnderline=FalseEn

13、dIfEndSube168PrivateSubForm_Load()Form1.Caption="框架用法示例”Command1.Caption="確定"Command2.Caption="結束"Frame1.Caption="字體類型"Frame2.Caption=”字體大小”O(jiān)ption1.Caption="魏碑"Option2.Caption="幼圓"Option3.Caption="16"Option4.Caption="24”Text1.Text

14、="VisualBasic程序設計"EndSubPrivateSubCommand1_Click()IfOptionlThenTextl.FontName="魏碑"ElseTextl.FontName="幼圓"EndIfIfOption3ThenTextl.FontSize=16ElseTextl.FontSize=24EndIfEndSubPrivateSubCommand2_Click()EndEndSub大小寫轉換PrivateSubCommand1_Click()Text1.Text="MicrosoftVisual

15、Basic6.0EndSubPrivateSubText1_Change()Text2.Text=LCase(Text1.Text)Text3.Text=UCase(Text1.Text)EndSub單選框PrivateSubRoman_Click()Display.FontSize=24Display.FontName="timesnewromanEndSubPrivateSubModern_Click()Display.FontSize=20Display.FontName="modern"EndSubPrivateSubCourier_Click()Disp

16、lay.FontSize=18Display.FontName="courier"EndSub紅綠燈PrivateSubForm_Load()Image2.Visible=FalseImage3.Visible=FalseEndSubPrivateSubCommand1_Click()IfImage1.Visible=TrueThenImage1.Visible=FalseImage2.Visible=TrueElseIfImage2.Visible=TrueThenImage2.Visible=FalseImage3.Visible=TrueElseImage3.Visi

17、ble=FalseImage1.Visible=TrueEndIfEndSubPrivateSubCommand2_Click()EndEndSub焦點DimtotalSubScore_LostFocus()x=Val(Score.Text)Ifx<0Orx>100ThenBeepScore.Text=""Score.SetFocusPrint”請重新輸入"Elsetotal=xEndIfEndSubSubCommand1_Click()PrinttotalEndSub例3.1單選按鈕與復選按鈕(常規(guī))PrivateSubCommand1_Click(

18、)IfOption1.Value=TrueThenText1.Font.Name="宋體"EndIfIfOption2.Value=TrueThenText1.Font.Name="黑體"EndIfIfOption3.Value=TrueThenText1.Font.Name="隸書"EndIfIfCheck1.Value=vbCheckedThenText1.Font.Bold=TrueElseText1.Font.Bold=FalseEndIfIfCheck2.Value=1ThenText1.Font.Italic=TrueEl

19、seText1.Font.Italic=FalseEndIfIfCheck3.Value=1ThenText1.Font.Underline=TrueElseText1.Font.Underline=FalseEndIfIfOption4.Value=TrueThenText1.Font.Size="8”EndIfIfOption5.Value=TrueThenText1.Font.Size="14”EndIfEndSubPrivateSubCommand2_Click()EndEndSubPrivateSubCheck4_Click()IfCheck4.Value=vbC

20、heckedThenTextI.ForeColor=vbRedElseText1.ForeColor=vbNormalEndIfEndSubPrivateSubCheck5_Click()IfCheck5.Value=vbCheckedThenText1.Font.Size="20”ElseText1.Font.Size="12"EndIfEndSubPrivateSubOption1_Click()IfOption1.Value=TrueThenText1.Font.Name="宋體"EndIfEndSubPrivateSubOption2_

21、Click()IfOption2.Value=TrueThenText1.Font.Name="黑體"EndIfEndSubPrivateSubOption3_Click()IfOption3.Value=TrueThenText1.Font.Name="隸書"EndIfEndSubPrivateSubCommand1_Click()Timerl.Enabled=FalseEndSubPrivateSubCommand2_Click()Timer1.Enabled=TrueEndSubPrivateSubCommand3_Click()EndEndSub

22、PrivateSubForm_Load()Timer1.Enabled=FalseTimer1.Interval=100EndSubPrivateSubTimer1_Timer()StatictAsIntegerIft=0ThenImage1.Picture=LoadPicture(App.Path+"bfly1.bmp")t=1ElseImage1.Picture=LoadPicture(App.Path+"bfly2.bmp")t=0EndIfEndSub例3.4蝴蝶飛舞DimsAsIntegerDims1AsIntegerPrivateSubCom

23、mand1_Click()Timer1.Enabled=FalseTimer2.Enabled=FalsePrivateSubCommand2_Click()Timerl.Enabled=TrueTimer2.Enabled=TrueEndSubPrivateSubCommand3_Click()EndEndSubPrivateSubForm_Load()Timer1.Enabled=FalseTimer1.Interval=100Timer2.Enabled=FalseTimer2.Interval=1000s=1:s1=1EndSubPrivateSubTimer1_Timer()Stat

24、ictAsIntegerIft=0ThenImage1.Picture=LoadPicture(App.Path+"bfly1.bmp")t=1ElseImage1.Picture=LoadPicture(App.Path+"bfly2.bmp")t=0EndIfEndSubPrivateSubTimer2_Timer()IfImage1.Top+Image1.Height>Form1.HeightThens1=-1ElseIfImage1.Top<0Thens1=1EndIfImage1.Top=Image1.Top+500*s1IfIma

25、ge1.Left+Image1.Width>Form1.WidthThens=-1ElselfImagel.Left<0Thens=1EndIfImagel.Left=Imagel.Left+500*sEndSub例3.5標簽的移動Dims1AsIntegerPrivateSubForm_Load()Label1=""Timer1.Enabled=FalseTimer2.Enabled=FalseTimer1.Interval=1000Timer2.Interval=100Timer1.Enabled=TrueTimer2.Enabled=TrueLabel2=

26、"歡迎光臨VB課堂"Label2.Font.Size="20”Label2.Font.Italic=TrueLabel2.Font.Bold=TrueLabel2.ForeColor=vbReds1=1EndSubPrivateSubTimer1_Timer()Label1.Caption="現(xiàn)在是:"&Hour(Time)&"時"&Minute(Time)_&"分"&Second(Time)&"秒"IfLabel2.ForeColor=

27、vbRedThenLabel2.ForeColor=vbBlueElseLabel2.ForeColor=vbRedEndIfEndSubPrivateSubTimer2_Timer()IfLabel2.Left+Label2.Width>Form1.WidthThens1=-1ElseIfLabel2.Left<0Thens1=1EndIfLabel2.Left=Label2.Left+50*siEndSub例3.6溫度計模擬PrivateSubCommand1_Click()Timerl.Enabled=TrueEndSubPrivateSubForm_Load()Timerl

28、.Enabled=FalseTimerl.Interval=100Label4.Visible=FalseVScrolll.Max=0VScrolll.Min=100EndSubPrivateSubTimer1_Timer()VScroll1.Value=VScroll1.Value+1EndSubPrivateSubVScroll1_Change()Label3.Caption="水溫:"&VScroll1.ValueIfVScrollI.Value=100ThenTimerl.Enabled=FalseLabel4.Visible=TrueEndIfEndSub

29、例3.7點菜單listboxPrivateSubCommand1_Click()List2.ClearEndSubPrivateSubCommand2_Click()EndEndSubPrivateSubCommand3_Click()DimiAsIntegerFori=0ToList1.ListCount-1IfList1.Selected(i)=TrueThenList2.AddItemList1.List(i)EndIfNextiList2.ListIndex=-1EndSubPrivateSubCommand4_Click()IfList2.ListIndex<>-1The

30、nList2.RemoveItemList2.ListIndexElseIfList2.ListCount=0ThenMsgBox"沒有可供刪除的項!ElseMsgBox"請先選擇,再刪除!"EndIfList2.ListIndex=-1PrivateSubForm_Load()Listl.AddItem"魚香肉絲"Listl.AddItem"宮爆雞丁"List1.AddItem"青菜蘑菇"List1.AddItem"四喜圓子"List1.AddItem”清蒸桂魚"List1

31、.AddItem"鐵板牛蛙"List1.AddItem"紅燒公雞"List1.ListIndex=-1EndSub例3.8調色板滾動條PrivateSubForm_Load()Label5.Caption="文字示例”Label5.Font.Size="16”Label5.Font.Bold=TrueEndSubPrivateSubHScroll1_Change()r=HScroll1.Valueg=HScroll2.Valueb=HScroll3.ValueLabel4.BackColor=RGB(r,g,b)Label5.Fore

32、Color=RGB(r,g,b)EndSubPrivateSubHScroll1_Scroll()r=HScroll1.Valueg=HScroll2.Valueb=HScroll3.ValueLabel4.BackColor=RGB(r,g,b)Label5ForeColor=RGB(r,g,b)EndSubPrivateSubHScroll2_Change()r=HScrollI.Valueg=HScroll2.Valueb=HScroll3.ValueLabel4.BackColor=RGB(r,g,b)Label5.ForeColor=RGB(r,g,b)EndSubPrivateSu

33、bHScroll2_Scroll()r=HScroll1.Valueg=HScroll2.Valueb=HScroll3.ValueLabel4.BackColor=RGB(r,g,b)Label5.ForeColor=RGB(r,g,b)EndSubPrivateSubHScroll3_Change()r=HScroll1.Valueg=HScroll2.Valueb=HScroll3.ValueLabel4.BackColor=RGB(r,g,b)Label5.ForeColor=RGB(r,g,b)EndSubPrivateSubHScroll3_Scroll()r=HScroll1.V

34、alueg=HScroll2.Valueb=HScroll3.ValueLabel4.BackColor=RGB(r,g,b)Label5.ForeColor=RGB(r,g,b)EndSub例3.9List控件的使用PrivateSubCommand1_Click()IfText1<>""ThenList1.AddItemText1List1.ListIndex=-1Label3.Caption=List1.ListCountText1=""Text1.SetFocusPrivateSubCommand2_Click()IfList1.Li

35、stIndex=-1ThenMsgBox”請先選擇!"ElseList1.RemoveItemList1.ListIndexEndIfLabel3.Caption=List1.ListCountEndSubPrivateSubForm_Load()List1.AddItem"趙一"List1.AddItem"趙二"List1.AddItem"張三"List1.AddItem"張四"List1.AddItem"張五"List1.AddItem"張六"List1.Add

36、Item"張七"Text1=""List1.ListIndex=-1Label3.Caption=List1.ListCountEndSub例3.11秒表演示OptionExplicitDimm%,s%,ms%PrivateSubCommand1_Click()Timer1.Enabled=TrueEndSubPrivateSubCommand2_Click()Timerl.Enabled=FalseEndSubPrivateSubForm_Load()Label2.FontSize=18Label2=”秒表演示程序"Timer1.Interv

37、al=10Timer1.Enabled=FalseLabel1.Caption=""Label1.FontSize=20Command1.Caption="開始"Command2.Caption="停止"EndSubPrivateSubTimer1_Timer()ms=ms+1Ifms>=100Thens=s+1:ms=0Ifs>=60Thenm=m+1:s=0Label1.Caption=m&"分"&s&"秒"&msEndSub例3.12倒計時程序D

38、imhAsInteger,mAsInteger,sAsIntegerPrivateSubCommand1_Click()Label1.Caption=""IfText1=""ThenMsgBox”請先輸入定時時間"Text1.SetFocusExitSubEndIfTimerl.Enabled=Truem=Val(Textl)s=60EndSubPrivateSubCommand2_Click()Timer1.Enabled=FalseEndSubPrivateSubForm_Load()Command1.Caption="開始&qu

39、ot;Command2.Caption="停止"Timer1.Interval=400Timer1.Enabled=FalseLabel1.Caption=""EndSubPrivateSubTimer1_Timer()s=s-1Ifs<=0Thenm=m-1:s=59Ifm=0ThenLabel1.Caption=""MsgBox"定時時間到!"Timer1.Enabled=FalseExitSubEndIfEndIfLabel1.Caption=m-1&"分"&s&am

40、p;"秒EndSub例3.13統(tǒng)計時間PrivatesAsInteger'聲明秒PrivatemAsInteger'聲明分PrivatehAsInteger'聲明小時PrivatedAsInteger'聲明日'啟動程序時設置Timer控件屬性并給秒、分、時、日變量賦值PrivateSubForm_Load()commandl.Caption="退出"Timer1.Enabled=TrueTimer1.Interval=1000s=0m=0h=0d=0EndSubPrivateSubTimer1_Timer()s=s+1

41、9;每秒鐘給s變量加1Ifs>=60Thens=0'重新計算秒m=m+1'逢秒為60則分鐘加1Ifm>=60Thenm=0'重新計算分h=h+1'逢分鐘為60則小時加1Ifh>=24Thenh=0'重新計算小時d=d+1'逢24小時則夭數(shù)加1EndIfEndIfEndIfEndSub'退出時PrivateSubcommand1_Click()Ifd*24+h>=1Then'使用時間若超過一小時MsgBox”本次使用的時間為:"&d*24+h&"小時"&m

42、&"分鐘"&s&"秒"&vbCrLf&"謝謝使用!"&vbCrLf&_”但請您注意休息,不要太勞累哦!",vbOKOnly,"再見"Else'若不超過一小時MsgBox”本次使用的時間為:"&h&"小時"&m&"分鐘"_&s&"秒"&vbCrLf&"謝謝使用!"&vbCrLf,vbO

43、KOnly,"再見"EndIfEndPrivateSubForm_queryunload(CancelAsInteger,UnloadmodeAsInteger)command1_Click'QueryUnload是在窗體關閉之前執(zhí)行的過程,Unload是窗體關閉時(也就是窗體從屏幕刪除時)執(zhí)行的過程,如果你的程序不允許關閉可以QueryUnload寫入相應的代碼。EndSub列表框PrivateSubForm_Load()Listl.AddItem"IBM"Listl.AddItem"DELL"Listl.AddItem&q

44、uot;HP"Listl.AddItem"FUJI"Listl.AddItem"方正"Listl.AddItem"長城"Listl.AddItem"聯(lián)想"Listl.AddItem"Canon"Listl.AddItem"四通"Listl.AddItem"Acer"Listl.AddItem"Nec"Listl.AddItem"NCR"EndSubPrivateSubList1_DblClick()List

45、2.AddItemListl.TextListl.RemoveItemListl.ListIndexEndSubPrivateSubList2_DblClick()Listl.AddItemList2.TextList2.RemoveItemList2.ListIndexEndSub時鐘613PrivateSubForm_Load()'Label1.FontName="魏碑Label1.Caption="字體"Label1.Width=WidthLabel1.Height=HeightTimer1.Interval=1000EndSubPrivateSub

46、Timer1_Timer()IfLabel1.FontSize<100ThenLabel1.FontSize=Label1.FontSize*1.2ElseLabel1.FontSize=10EndIfEndSub時鐘614PrivateSubForm_Load()Command1.Caption="開始"Command2.Caption="停止"Timer1.Interval=50Timer1.Enabled=FalseLabel1.Caption="熱烈歡迎"Label1.AutoSize=TrueLabel1.FontSi

47、ze=16Label1.FontBold=TrueEndSubPrivateSubCommand1_Click()Command1.Caption="繼續(xù)"Timer1.Enabled=TrueCommand1.Enabled=FalseCommand2.Enabled=TruePrivateSubCommand2_Click()Timerl.Enabled=FalseCommand2.Enabled=FalseCommand1.Enabled=TrueEndSubPrivateSubTimer1_Timer()IfLabel1.Left<WidthThenLabel

48、1.Left=Label1.Left+20ElseLabel1.Left=0EndIfEndSub校驗密碼PrivateSubCommand1_Click()IfText1.Text="123456”ThenText2.Text="密碼正確,繼續(xù)"ElseText2.Text="密碼錯誤,重新輸入"EndIfEndSubPrivateSubCommand2_Click()Text1.Text=""Text2.Text=""Text1.SetFocusEndSub第七章DimnAsSingleDimn1As

49、SingleDimn2AsSingleDimscoreAsSingleDimtotalAsSinglePrivateSubCommand1_Click()msg$="請輸入分數(shù)(-1結束)msgtitle$="輸入數(shù)據(jù)"start:score=InputBox(msg$,msgtitle$)score=Val(score)Ifscore<0Orscore>100ThenGoToFinishElsetotal=total+scoren=n+1Ifscore<60Thenn1=n1+1Elsen2=n2+1EndIfEndIfGoTostartFin

50、ish:EndSubPrivateSubCommand2_Click()Text1.Text=Str$(n2)Text2.Text=Str$(n1)Text3.Text=Str$(total/n)EndSubPrivateSubCommand3_Click()n=0:n1=0:n2=0:total=0EndEndSubSubForm_Click()DimMsg,UserinputMsg=”請輸入一個字母或0到9的數(shù)"Userinput=InputBox(Msg)IfNotIsNumeric(Userinput)ThenIfLen(Userinput)<>0ThenSele

51、ctCaseAsc(UserInput)Case65To90'大寫字母Msg="你輸入的是大定字母'"Msg=Msg&Chr(Asc(UserInput)&"'Case97To122'小寫字母Msg="你輸入的是小定字母'"Msg=Msg&Chr(Asc(UserInput)&"'CaseElseMsg="你輸入的不是字母或數(shù)字"EndSelectEndIfElseSelectCaseCDbl(UserInput)Case1,3,5,7

52、,9'奇數(shù)Msg=UserInput&"是一個奇數(shù)."Case0,2,4,6,8'偶數(shù)Msg=UserInput&"是一個偶數(shù)."CaseElse'出界Msg="你輸入了一個超出范圍的數(shù)"EndSelectEndIfMsgBoxMsgEndSubSubForm_Click()DimNAsIntegerN=InputBox("EnterN:")k=1Fori=1ToNk=k*iNextiPrintN;"!="kEndSubSubForm_Click()Dim

53、numberAsIntegerNegativeSum=0:PositiveSum=0Fori=1To10number=InputBox("EnterData:")Ifnumber<0ThenPrintnumber;NegativeSum=NegativeSum+numberElsePositiveSum=PositiveSum+numberEndIfNextiPrintPrint"Negativesumis:"NegativeSumPrint"Positivesumis:"PositiveSumEndSubSubForm_Cli

54、ck()DimcharAsStringConstch$="?”Counter=0msg$="Enteracharacter:"char=InputBox$(msg$)Whilechar<>ch$Counter=Counter+1char=InputBox$(msg$)WendPrint"Numberofcharactersentered:"CounterEndSubSubForm_Click()DimnAsIntegern=InputBox("請輸入一個正整數(shù)(>=3)”)k=Int(Sqr(n)i=2Swit=0W

55、hilei<=kAndSwit=0IfnModi=0ThenSwit=1Elsei=i+1EndIfWendIfSwit=0ThenPrintn;"是一個素數(shù)"ElsePrintn;"不是素數(shù)"EndIfEndSubSubForm_Click()DimpAsDoubleDimrAsSingleDimnAsIntegerp=6000000000#r=0.014n=0DoUntilp>=7000000000#p=p*(1+r)n=n+1LoopPrintn;"年后""世界人口達"pEndSubPrivate

56、SubCommand1_Click()DimaAsSingle,xn0AsSingle,xn1AsSinglea=InputBox("請輸入一個正數(shù)",”求平方根")a=Val(a)xn0=a/2xn1=(xn0+a/xn0)/2Doxn0=xn1xn1=(xn0+a/xn0)/2LoopWhileAbs(xn0-xn1)>=0.00001Printa;"的平方根是:"xn1EndSubPrivateSubCommand2_Click()EndEndSubPrivateSubForm_Click()PrintTab(30);"9

57、*9Table"Print:PrintPrint"*"Fori=1To9PrintTab(i*6);i;NextiPrintForj=1To9Printj;""Fork=1Tojtemp=j*kPrintTab(k*6);temp;""NextkPrintNextjEndSubSubForm_Click()Forn=101To300Step2k=Int(Sqr(n)i=2swit=0Whilei<=kAndswit=0IfnModi=0Thenswit=1Elsei=i+1EndIfWendIfswit=0Thend=

58、d+1IfdMod5=0ThenPrintn;"PrintElsePrintn;"EndIfEndIfNextnEndSubSubForm_Click()DimI,NumDoForI=1To1000Num=Int(Rnd*100)PrintNum;SelectCaseNumCase7:ExitForCase29:ExitDoCase54:ExitSubEndSelectNextIPrint"ExitFor"LoopPrint"exitDo"EndSubSubForm_Click()DimpAsCurrencyp=10000:r=0.1

59、25t=1Again:Ift>10ThenGoTo100i=p*rp=p+it=t+1GoToAgain100PrintpEndSub第八章例4.1簡易計算器控件數(shù)組DimxAsSingle,yAsSingleDimopAsStringPrivateSubCommand1_Click(IndexAsInteger)SelectCaseIndexCase0To9,14Text1.Text=Text1&Command1(Index).CaptionCase10To13x=Val(Text1)Text1=""IfIndex=10Thenop="+"

60、;IfIndex=11Thenop="-"IfIndex=12Thenop="*”IfIndex=13Thenop="/"Case15y=Val(Text1)Text1=""Ifop="+"ThenText1=x+yIfop="-"ThenText1=x-yIfop="*"ThenText1=x*yIfop="/"ThenText1=x/yCase16Text1=Left(Text1,Len(Text1)-1)Case17Text1="

61、"Case18x=Val(Text1):Text1=Sqr(x)Case19x=Val(Text1):Text1=x*xEndSelectEndSubPrivateSubForm_Load()Text1=""EndSub例4.2計算器DimxAsSingle,yAsSingleDimopAsStringPrivateSubCommand1_Click(IndexAsInteger)SelectCaseIndexCase0To9Text1.Text=Text1&Command1(Index).CaptionCase14IfInStr(Text1,”.”)=0

62、ThenTextl.Text=Textl&Command1(Index).CaptionElselfRight(Text1,1)="."ThenText1.Text=Text1&""EndIfCase10To13x=Val(Text1)IfIndex=10Thenop="+"IfIndex=11Thenop="-"IfIndex=12Thenop="*”IfIndex=13Thenop="/"Text1=""Case15y=Val(Text1)

63、9;Text1=""Ifop="+"ThenText1=x+yIfop="-"ThenText1=x-yIfop="*"ThenText1=x*yIfop="/"ThenIfy<>0ThenText1=x/yElseText1="除數(shù)不能為零"EndIfEndIfCase16IfLen(Text1)<>0ThenText1=Left(Text1,Len(Text1)-1)EndIfCase17Text1=""x=0:y=0Case1

64、8x=Val(Text1)Ifx<0ThenText1="負數(shù)的平方根無意義"ElseText1=Sqr(x)EndIfCase19x=Val(Textl):Textl=x*xCase20x=Val(Textl):Textl=Sin(x*3.1415926/180)Case21x=Val(Text1):Text1=Cos(x*3.1415926/180)Case22x=Val(Text1):Text1=Tan(x*3.1415926/180)Case23x=Val(Text1):Text1=Atn(x)*180/3.1415926Case24x=Val(Text1)I

65、fx<=0ThenText1="負數(shù)或零的對數(shù)無意義"ElseText1=Log(x)EndIfEndSelectEndSubPrivateSubForm_Load()Text1=""Fori=0To24Command1(i).BackColor=&HC0FFFFNextiEndSubStaticSubForm_Click()DimTest(1To20)AsIntegerFori=1To20Test(i)=iPrintTest(i);NextiEraseTestPrintPrint"EraseTest()"Print&q

66、uot;NowtheTestArrayisFilledwithzeros.Fori=1To20PrintTest(i);NextiEndSubSubCommand1_Click()Staticnumber(1To10)AsIntegermsg$="Enternumberforsort:"msgtitle$="SortDemo"Fori%=1To10number(i%)=InputBox(msg$,msgtitle$)Nexti%Fori%=10To2Step-1Forj%=1Toi%-1Ifnumber(j%)>number(j%+1)Thent=

67、number(j%+1)number(j%+1)=number(j%)number(j%)=tEndIfNextj%Nexti%Fori%=1To10Printnumber(i%)Nexti%EndSubOptionBase1PrivateSubForm_Click()DimaaaAsVariantMyWeek=Array("Mon","Tue","Wed","Thu","Fri","Sat","Sun")myday2=MyWeek(2)'MyDay2contains"Tue".myday3=MyWeek(4)'MyDay3contains"Thu".Printmyday2,myday3aaa=

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論