版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、編寫(xiě)一個(gè)函數(shù)fib.該函數(shù)可以求數(shù)列1,1,2,3,5,8,13,21……的第n(1<=n<=20)項(xiàng),將第N項(xiàng)的值作為函數(shù)的返回值。Functionfib(nAsInteger)AsLongIfn=1Thenfib=1Ifn=2Thenfib=1Ifn>=3Andn<=20Thenfib=fib(n-1)+fib(n-2)EndFunction以上是定義函數(shù),下面是主程序調(diào)用函數(shù)PrivateSubCommand1_Click()DimiAsIntegerFori=1To20Printfib(i);‘加分號(hào),橫行輸出Ifimod5=0Thenprint‘每行輸出5個(gè)NextiEndSub2、下面程序用于統(tǒng)計(jì)一個(gè)班級(jí)的某科成績(jī),成績(jī)百分制。要求所有成績(jī)由鍵盤輸入,輸入負(fù)數(shù)認(rèn)為輸入結(jié)束,輸出數(shù)據(jù)為班級(jí)人數(shù)、最高分是、最低分和平均分。PrivateSubCommand1_Click()Dimf()AsSingleDimminAsSingle,maxAsSingle,nAsIntegerDimsAsSingle,kAsSingle,iAsSingleDimtAsSinglei=1s=InputBox("輸入成績(jī)1:")DoWhiles>=0‘s<0時(shí)就停止循環(huán)ReDimPreservef(1Toi)f(i)=si=i+1s=InputBox("輸入成績(jī)"&i)Loopi=i–1‘停止循環(huán)時(shí)I多加1,負(fù)數(shù)不計(jì)數(shù)min=f(1)‘將f(1)置為minmax=f(1)‘將f(1)置為maxForn=1ToiIfmax<f(n)Thenmax=f(n)Ifmin>f(n)Thenmin=f(n)t=t+f(n)‘計(jì)算總分Nextk=t/i‘計(jì)算平均分Print"總?cè)藬?shù)是:"&i&"人"&","&"平均分是:"&kPrint"最高分是:"&max&","&"最低分是:"&minEndSub3、窗口有三個(gè)控件,命令按鈕Command1、圖片框1和圖片框二,單擊按鈕時(shí)先為picture1加載圖片(f:\123.jpg),然后將picture1里的圖片復(fù)制到picture2中并實(shí)現(xiàn)水平反轉(zhuǎn)。PrivateSubCommand1_Click()Picture1.Picture=LoadPicture("f:\123.jpg")Picture2.PaintPicturePicture1.Picture,_0,0,Picture1.ScaleWidth,Picture1.ScaleHeight,Picture1.ScaleWidth,0,-Picture1.ScaleWidth,Picture1.ScaleHeight‘目標(biāo)區(qū)域左上角,目標(biāo)寬高,開(kāi)始復(fù)制點(diǎn),繪圖大小EndSub4、有分段函數(shù)Sin(x)+1x0f(x)=sin(x)+cos(x)0<x,當(dāng)單擊command1時(shí)將在窗口中繪制[-,2]的圖形。cos(x)-sin(x)x>PrivateSubCommand1_Click()DimxAsSingleDimyAsSingleConstpi=3.1415926Me.Scale(-5,3)-(10,-3)Forx=-piTo2*piStep0.002Ifx<=0Theny=Sin(x)+1ElseIfx<=piTheny=Cos(x)+Sin(x)ElseIfx<=2*piTheny=Cos(x)-Sin(x)EndIfMe.PSet(x,y),vbRedNextxMe.Line(-5,0)-(8,0),vbBlueMe.Line(0,-2.5)-(0,2.5),vbBlueEndSub5、畫(huà)圖y=sin(x)PrivateSubCommand1_Click()'Me.ScaleHeight=-4'首先設(shè)置系統(tǒng)坐標(biāo),高度值設(shè)為負(fù)數(shù),以向上為正'Me.ScaleLeft=-3'Me.ScaleTop=2'Me.ScaleWidth=12'這四句相當(dāng)于me.scale(-4,3)-(8,-3)Constpi=3.1415926'常量定義方式,方便后面使用DimxAsSingleDimyAsSingleDimtAsSingleForx=0To2*piStep0.0002'在0到2pi上用Pset畫(huà)點(diǎn)函數(shù)來(lái)畫(huà)正弦曲線,步長(zhǎng)盡量取小y=Sin(x)Me.PSet(x,y),vbRedNextxForx=-2To8Step0.0002'畫(huà)橫軸,從-2到8,也可用line函數(shù)來(lái)畫(huà)Me.PSet(x,0),vbBlueNextxMe.Line(0,1.5)-(0,-1.5),vbBlue'畫(huà)縱軸,從-1.5到1.5Me.Line(7.8,0.1)-(8,0),vbBlueMe.Line(7.8,-0.1)-(8,0),vbBlueMe.Line(-0.2,1.3)-(0,1.5),vbBlueMe.Line(0.2,1.3)-(0,1.5),vbBlue'這四句畫(huà)坐標(biāo)軸箭頭Forx=-1To7Line(x,0)-(x,0.1),vbBlue'在橫軸上畫(huà)小箭頭Ifx<>0ThenMe.CurrentX=x-0.2Me.CurrentY=-0.1Printx'在合適的位置輸出數(shù)值的標(biāo)識(shí)ElseMe.CurrentX=0Me.CurrentY=-0.1Print"(0,0)"'在合適的位置輸出(0,0)標(biāo)識(shí)EndIfNextx'Me.Line(0,1)-(0.2,1),vbBlue'Me.CurrentX=-0.3'Me.CurrentY=1'Print"1"'Me.Line(0,-1)-(0.2,-1),vbBlue'Me.CurrentX=-0.3'Me.CurrentY=-1'Print"-1"Fort=-1To1Step0.5'在縱軸上輸出小間隔和標(biāo)識(shí)Line(0,t)-(0.2,t),vbBlueIft<>0ThenMe.CurrentX=-0.5Me.CurrentY=tPrinttElsePrint""EndIfNexttEndSub6、fibonacci數(shù)列:1,1,2,3,5,8,13,21……PrivateSubCommand1_Click()Dimf()AsDouble,iAsInteger'這里使用數(shù)組重定義,表示數(shù)組長(zhǎng)度會(huì)發(fā)生變化ReDimf(1To48)f(1)=1f(2)=1Fori=3To48f(i)=f(i-1)+f(i-2)NextiFori=1To48Printf(i),'末尾加逗號(hào),橫行輸出IfiMod6=0ThenPrint'每輸出六個(gè)數(shù)換一行NextiReDimPreservef(1To84)'preserve函數(shù)保留之前的值Me.ForeColor=vbRedFori=49To84f(i)=f(i-1)+f(i-2)NextiFori=1To84Printf(i),IfiMod6=0ThenPrintNextiEndSub7、楊輝三角PrivateSubCommand1_Click()Me.Cls‘清屏PrintTab(48),"楊輝三角"'空48格,輸出標(biāo)題DimiAsInteger,jAsInteger'i定義為行,j定義為列Dimy(1To7,1To7)AsInteger'定義y是一個(gè)7*7的二維數(shù)組Fori=1To7y(i,1)=1'第一列全是1y(i,i)=1'對(duì)角線上全是1Nexti'接下來(lái)輸出中間的數(shù)Fori=3To7'輸出3到7行Forj=2Toi-1y(i,j)=y(i-1,j-1)+y(i-1,j)'中間數(shù)等于上面一行相鄰兩數(shù)相加NextjNextiFori=1To7Forj=1ToiPrinty(i,j),'末尾加逗號(hào),橫行輸出NextjPrintNextiEndSub8、讀寫(xiě)文件OptionExplicitPrivateTypes'定義結(jié)構(gòu)體xmAsString*10nlAsIntegercjAsSingleEndTypeDimaAssPrivateSubCommand1_Click()C.ShowOpen‘通用對(duì)話框打開(kāi)OpenC.FileNameForOutputAs#1'output寫(xiě)文件,input為讀文件a.xm=Text1.Texta.nl=Val(Text2.Text)a.cj=Val(Text3.Text)Print#1,a.xmPrint#1,a.nlPrint#1,a.cj'Write#1,a.xm,a.nl,a.cj'write寫(xiě)文件其中有分隔符,print沒(méi)有分隔符Close#1EndSubPrivateSubCommand2_Click()DimiAsIntegerText1.Text=""Text2.Text=""Text3.Text=""C.ShowSaveDimlAsIntegerDimsAsStringOpenC.FileNameForInputAs#1l=LOF(1)DoWhileNotEOF(1)LineInput#1,sText1.Text=Text1.Text&s&Chr(13)&Chr(10)LoopClose#1EndSub9、畫(huà)圖程序中畫(huà)筆部分DimgongjuAsStringDimyanseAsLongDimxxAsSingle,yyAsSinglePrivateSubForm_Load()yanse=vbBluePicture4.BackColor=yansegongju="筆"EndSubPrivateSubOption1_Click(IndexAsInteger)SelectCaseIndexCase0gongju="筆"Case1gongju="直線"Picture3.Visible=TrueCase2gongju="橡皮"EndSelectEndSubPrivateSubPicture1_MouseDown(ButtonAsInteger,ShiftAsInteger,xAsSingle,yAsSingle)SelectCasegongjuCase"筆"IfButton=1ThenPicture1.CurrentX=xPicture1.CurrentY=yEndIfCase"橡皮"Case"直線"EndSelectEndSubPrivateSubPicture1_MouseMove(ButtonAsInteger,ShiftAsInteger,xAsSingle,yAsSingle)SelectCasegongjuCase"筆"IfButton=1ThenPicture1.Line-(x,y),yanseEndIfCase"橡皮"Case"直線"EndSelectEndSub‘畫(huà)筆無(wú)mouseup事件,直線有Case"橡皮"Case"直線"EndSelectEndSubPrivateSubPicture2_Click(IndexAsInteger)‘選擇畫(huà)筆顏色,picture2為控件數(shù)組yanse=Picture2(Index).BackColor‘把選中的顏色置為yansePicture4.BackColor=yanse‘在picture4中顯示當(dāng)前顏色EndSub10、計(jì)算器OptionExplicitDimaAsSingle,bAsSingle,tAsSingleDimopAsString*1DimqingAsBooleanDimmAsSinglePrivateSubCommand1_Click(IndexAsInteger)‘?dāng)?shù)字鍵控件數(shù)組Ifqing=TrueThenLabel1.Caption=""‘再次運(yùn)算時(shí)清空顯示qing=FalseEndIfLabel1.Caption=Label1.Caption&Command1(Index).CaptionEndSubPrivateSubCommand10_Click()‘MRLabel1.Caption=mEndSubPrivateSubCommand11_Click()‘M+IfLabel2.Caption=""Thenm=m+Val(Label1.Caption)EndIfIfLabel1.Caption<>""Thenm=m+Val(Label1.Caption)Label2.Caption="m"EndIfEndSubPrivateSubCommand12_Click()‘MCLabel2.Caption=""m=0EndSubPrivateSubCommand13_Click()‘+/-Label1.Caption=-Val(Label1.Caption)EndSubPrivateSubCommand14_Click()‘小數(shù)點(diǎn)Ifqing=TrueThenLabel1.Caption=""qing=FalseEndIfIfInStr(1,Label1.Caption,".")=0ThenLabel1.Caption=Label1.Caption&"."EndIfEndSubPrivateSubCommand2_Click(IndexAsInteger)‘控件數(shù)組+-*/qing=Truea=Val(Label1.Caption)Label1.Caption=""op=Command2(Index).CaptionEndSubPrivateSubCommand3_Click()‘等號(hào)qing=Trueb=Val(Label1.Caption)'SelectCaseop'Caseop="+"'t=a+b'Caseop="-"'t=a-b'Caseop="*"'t=a*b'Caseop="/"'Ifb=0ThenLabel1.Caption="除數(shù)不能為零"'ExitSub't=a/b'EndSelectIfop="+"Thent=a+bEndIfIfop="-"Thent=a-bEndIfIfop="*"Thent=a*bEndIfIfop="/"ThenIfb=0ThenLabel1.Caption="除數(shù)不能為零"Elset=a/bEndIfEndIfLabel1.Caption=tEndSubPrivateSubCommand4_Click()‘CELabel1.Caption=""EndSubPrivateSubCommand5_Click()‘BackspaceIfLabel1.Caption<>""ThenLabel1.Caption=Left(Label1.Caption,Len(Label1.Caption)-1)EndIfEndSubPrivateSubCommand6_Click()‘Ca=0Label1.Caption=""EndSubPrivateSubCommand7_Click()‘sqrtLabel1.Caption=Sqr(Val(Label1.Caption))qing=TrueEndSubPrivateSubCommand8_Click()‘1/xIfVal(Label1.Caption)<>0ThenLabel1.Caption=1/Val(Label1.Caption)ElseLabel1.Caption="分母不能為零"EndIfqing=TrueEndSubPrivateSubCommand9_Click()IfLabel1.Caption<>""Thenm=Val(Label1.Caption)Label2.Caption="m"EndIfEndSubPrivateSubForm_Load()qing=TrueIfqing=TrueThenLabel1.Caption=""qing=FalseEndIfop="+"EndSub11、把列表框中的古詩(shī)在單擊command1按鈕時(shí)將所有詩(shī)句以順序文件形式寫(xiě)入F盤的gushi.txt文件中。PrivateSubCommand1_Click()Open"f:\gushi.txt"ForOutputAs#1DimiAsIntegerFori=0ToL.ListCount-1Print#1,L.List(i)NextClose#1EndSub12、編寫(xiě)一個(gè)函數(shù)S利用缺省函數(shù)的特性來(lái)求矩形面積(矩形可能是:正方形、長(zhǎng)方形、梯形),若只有一個(gè)參數(shù)a則認(rèn)為求正方形面積,有兩個(gè)參數(shù)a,b,認(rèn)為求長(zhǎng)方形面積,有三個(gè)參數(shù)a,b,h,認(rèn)為求梯形面積。Functions(aAsSingle,Optionalb,Optionalh)AsSingleIfIsMissing(h)=TrueThenIfIsMissing(b)=TrueThens=a*aElses=s*bEndIfElses=(a+b)*h/2EndIfEndFunctionPrivateSubCommand1_Click()Prints(5)EndSub13、編寫(xiě)一個(gè)函數(shù),求任意個(gè)浮點(diǎn)數(shù)的平均值,函數(shù)的返回值為求得的結(jié)果。Functionp(ParamArraya())AsDoubleDimbAsVariant,sAsDouble,nAsIntegerForEachbInas=s+bn=n+1Nextbp=s/nEndFunction多窗體的應(yīng)用程序只能包含一個(gè)MDI(父窗口),可以包含多個(gè)SDI(子窗口),父窗口要先于子窗口加載,但卸載時(shí)晚于子窗口圖像框(image)中的圖像可以隨控件大小自動(dòng)縮放(stretch屬性為false;為true時(shí)會(huì)使圖片適應(yīng)相框大?。瑘D片框(picturebox)把a(bǔ)utosize屬性置為true系統(tǒng)會(huì)自動(dòng)改變控件大小以適應(yīng)要加載圖片單選按鈕控件數(shù)組要放在同一個(gè)框架中(同一容器),并只能有一個(gè)控件被選中(value=true)通用的函數(shù)有返回值,通用的過(guò)程沒(méi)有返回值,函數(shù)可以通過(guò)call來(lái)調(diào)用具有value屬性的控件:滾動(dòng)條(scrollbar)、復(fù)選框checkbox(1選中,0未選中)、單選按鈕optionbutton(ture/false)組合框控件style屬性:0可輸入可選,1輸入,2只能選擇對(duì)于一個(gè)正常的窗體來(lái)說(shuō),terminate是最后發(fā)生的,initialize(初始化)是最早發(fā)生的。使控件獲取焦點(diǎn),用setfocus方法多窗體工程用unloadme語(yǔ)句可以卸載SDI窗體(本窗口),但不會(huì)影響其他窗口運(yùn)行,用end方法可以終止程序10、文本框具有passordchar屬性,也就是掩碼11、Visible屬性是可見(jiàn)性,me.hide相當(dāng)于form1.visible=true,enable屬性是可用性,command1.enable=false,表示command1按鈕呈灰色不可用12、強(qiáng)制變量聲明:optionexplicit13、“56”+“23”=“5623”“56”+23=7914、實(shí)參是主程序中的參數(shù),形參是被調(diào)用函數(shù)或者過(guò)程中的參數(shù),Byref是傳地址,是默認(rèn)值,形參和實(shí)參要互相影響;Byval是傳值,實(shí)參和形參之間不影響15、for循環(huán)中的步長(zhǎng)默認(rèn)為1如Fori=1to10(step1)……Nexti如果循環(huán)是從大數(shù)到小數(shù),步長(zhǎng)為-1時(shí),要寫(xiě)明step-1,不符合循環(huán)條件時(shí),中間退出循環(huán)(for語(yǔ)句應(yīng)exitfor;doloop語(yǔ)句用exitdo),否則看循環(huán)條件,循環(huán)完畢自動(dòng)退出。循環(huán)結(jié)構(gòu)還有Dowhile條件do…………LoopLoopwhie條件16、選擇語(yǔ)句有單分支if條件thenif條件then……(不用endif)……Endif多分支中間加elseif條件then……17、列表框中添加條目用list1.additem+要添加的字符,用雙引號(hào);刪除條目用list1.removeitem+index(索引號(hào))第一行索引號(hào)為0,要清除列表框中的所有內(nèi)容用list1.clear18、keydown和keyup是兩個(gè)成對(duì)出現(xiàn)的事件,只要按下鍵盤按鍵就會(huì)發(fā)生,keypress是檢測(cè)按鍵的ascii碼,所以只在能產(chǎn)生ascii碼的按鍵按下時(shí)才會(huì)發(fā)生;mousedown和mouseup是成對(duì)出現(xiàn)的事件,mousmove是移動(dòng)鼠標(biāo)時(shí)觸發(fā)的事件。19、通用對(duì)話框(commondialog)是無(wú)法完成文件的打開(kāi)和保存操作的,它只提供要操作文件的地址20、窗體的scaleleft和scaletop是指窗體中的坐標(biāo)原點(diǎn)距離左邊和上邊界位置,scaleheight和scalewidth是指窗體中坐標(biāo)的左右和上下的跨度。窗體的絕對(duì)大小由height和width值來(lái)確定,left和top值是確定窗體在運(yùn)行時(shí)距離左邊界和上邊界的位置。后面四個(gè)屬性值對(duì)于command等控件也相應(yīng)適用。21、控件的事件集是控件所固有的,不能人為的添加或刪除。22、timer控件只有一個(gè)事件:timer事件,把它的interval置為0時(shí)就不觸發(fā)timer事件23、circle語(yǔ)句可以畫(huà):圓、弧、橢圓24、要使窗體上print語(yǔ)句輸出的信息不隨著窗口的刷新而丟失,應(yīng)將窗體的autoredraw屬性置為ture。25、inputbox輸出的是字符,在進(jìn)行數(shù)值計(jì)算時(shí),為避免系統(tǒng)報(bào)錯(cuò),用val函數(shù)轉(zhuǎn)化成數(shù)值K=val(inputbox(“請(qǐng)輸入第”&I&“個(gè)成績(jī)”))26、open文件名forinput(讀?。ù蜷_(kāi)模式)as#1Output(寫(xiě)入)Lineinput#1,s‘將#1文件中的字符寫(xiě)入sList1.additems‘將添加進(jìn)列表框中Noteof(文件號(hào))‘還沒(méi)到文件最后一行27、picture1加載圖片picture1.picture=loadpicture(”文件地址”)28、打開(kāi)二進(jìn)制文件,打開(kāi)模式為(binary),打開(kāi)隨機(jī)文件,打開(kāi)模式為(random),讀取二進(jìn)制文件要用(get)語(yǔ)句,寫(xiě)隨機(jī)文件要用(put)語(yǔ)句29、open“123.txt“foroutputas#1print#1,“要添加的字符“‘向#1文件中寫(xiě)字符Close#1Open“123.txt”forinputas#1Text1.text=input(5,#1)‘把#1文件中的前5個(gè)字符添加進(jìn)text1里面Close#130、在定義中,private表示此過(guò)程只可以被本窗體模塊中的其他函數(shù)和過(guò)程調(diào)用。對(duì)應(yīng)的還有public公有過(guò)程PrivateSubCommand1_Click()DimXAsSingle,YAsSingle,TAsSingleDimOpAsString*1X=InputBox("數(shù)據(jù)1")Op=InputBox("運(yùn)算符")Y=InputBox("數(shù)據(jù)2")IfOp="+"OrOp="-"OrOp="*"OrOp="/"ThenIfOp="+"ThenT=X+YElseIfOp="-"ThenT=X-YElseIfOp="*"ThenT=X*YElseIfOp="/"ThenT=X/YEndIfPrintX&Op&Y&"="&TElseMsgBox"運(yùn)算符都不會(huì)輸入,不和你玩!"EndIfEndSub5計(jì)算器OptionExplicitDimOpAsString*1DimXAsSingleDimqingAsBooleanDimmAsSinglePrivateSubbacks_Click()IfL.Caption<>""ThenL.Caption=Left(L.Caption,Len(L.Caption)-1)EndIfEndSubPrivateSubC_Click()X=0L.Caption=""EndSubPrivateSubCE_Click()L.Caption=""EndSubPrivateSubCommand2_Click()Frame1.Enabled=NotFrame1.EnabledEndSubPrivateSubdaos_Click()qing=TrueL.Caption=1/Val(L.Caption)EndSubPrivateSubdeng_Click()DimYAsSingle,TAsSingleqing=True'x=InputBox("數(shù)據(jù)1")'op=InputBox("運(yùn)算符")'y=InputBox("數(shù)據(jù)2")Y=Val(L.Caption)SelectCaseOpCase"+"T=X+YCase"-"T=X-YCase"*"T=X*YCase"/"IfY=0ThenL.Caption="除數(shù)不能為零!"ExitSubElseT=X/YEndIfEndSelect'Printx&op&y&"="&tL.Caption=TEndSubPrivateSubdian_Click()Ifqing=TrueThenL.Caption=""qing=FalseEndIfIfInStr(L.Caption,".")=0ThenL.Caption=L.Caption&"."EndIfEndSubPrivateSubfuhao_Click()DimaAsSinglea=-Val(L.Caption)L.Caption=aEndSubPrivateSubkaif_Click()qing=TrueL.Caption=Sqr(Val(L.Caption))EndSubPrivateSubMADD_Click()IfVal(L.Caption)<>0Thenm=m+Val(L.Caption)LL.Caption="M"EndIfEndSubPrivateSubMC_Click()m=0LL.Caption=""EndSubPrivateSubMR_Click()L.Caption=mEndSubPrivateSubMS_Click()IfVal(L.Caption)<>0Thenm=Val(L.Caption)LL.Caption="M"EndIfEndSubPrivateSubN_Click(IndexAsInteger)Ifqing=TrueThenL.Caption=""qing=FalseEndIfL.Caption=L.Caption&N(Index).CaptionEndSubPrivateSubops_Click(IndexAsInteger)X=Val(L.Caption)qing=TrueOp=ops(Index).CaptionEndSub簡(jiǎn)單計(jì)算器6PrivateSubN_Click(IndexAsInteger)Ifqing=TrueThenL.Caption=""qing=FalseEndIfL.Caption=L.Caption&N(Index).CaptionEndSubPrivateSubqufu_Click()L.Caption=-Val(L.Caption)EndSubPrivateSubysf_Click(IndexAsInteger)C=C+1IfC=1ThenX=Val(L.Caption)qing=TrueOp=ysf(Index).CaptionElseIfC=2ThenDimYAsDouble,TAsDoubleqing=TrueY=Val(L.Caption)SelectCaseOpCase"+"T=X+YCase"-"T=X-YCase"*"T=X*YCase"/"IfY<>0ThenT=X/YElseL.Caption="除數(shù)為零!"ExitSubEndIfEndSelectL.Caption=TX=Val(L.Caption)Op=ysf(Index).CaptionC=1EndIfEndSub5PrivateSubCommand1_Click()DimHAsSingle,bAsIntegerDimsAsIntegers=1b=1Do'WhileB<=5H=H+bb=b+1LoopUntilb>5PrintH,bEndSubPrivateSubCommand2_Click()DimXAsSingle,YAsIntegerForX=100To1Step-1Y=Y+XNextXPrintY,XEndSubPrivateSubCommand3_Click()DimIDimaAsIntegerForEachIInCa=a+I.CaptionNextIMsgBoxaEndSub6九九乘法表PrivateSubCommand1_Click()DimIAsInteger,jAsIntegerDimaAsIntegera=Me.FontSizeMe.FontSize=20Me.ForeColor=vbRedPrintPrint"-------------------------"&"九九乘法表"&_"-------------------------"PrintMe.FontSize=aMe.ForeColor=vbBlackI=1DoWhileI<=9j=1DoPrintj&"*"&I&"="&I*j,j=j+1LoopUntilj>IPrintIfI=9ThenExitDoI=I+1LoopEndSub7養(yǎng)兔子PrivateFunctions1(XAsInteger,YAsInteger)AsIntegers1=X+YEndFunctionPrivateSubCommand1_Click()DimmAsSingle,eAsSingle,aAsSinglem=14e=64a=(m+e)/2PrintaEndSub兔子PrivateSubCommand3_Click()Dimf()AsSingleDimIAsIntegerDimNAsIntegerPrintDoN=InputBox("說(shuō)打算養(yǎng)幾個(gè)月?")LoopWhileN<0IfN>=2ThenReDimf(1ToN)f(1)=1f(2)=1ForI=3ToUBound(f)f(I)=f(I-1)+f(I-2)NextIForI=1ToUBound(f)Printf(I),IfIMod5=0ThenPrintNextIMe.ForeColor=vbBluePrintReDimf(1ToN+10)ForI=N+1ToUBound(f)f(I)=f(I-1)+f(I-2)NextIForI=1ToUBound(f)Printf(I),IfIMod5=0ThenPrintNextIElseIfN=1ThenMsgBox("一只大笨兔")ElseMsgBox("一只大笨兔也沒(méi)有")EndIfEndSub楊輝三角PrivateSubCommand4_Click()Dima(1To10,1To10)AsIntegerDimN,mAsIntegerForN=1To10a(N,N)=1a(N,1)=1NextNForN=3To10Form=2ToN-1a(N,m)=a(N-1,m-1)+a(N-1,m)NextmNextNForN=3To10Form=1ToNPrinta(N,m),NextmPrintNextNEndSubPrivateFunctionsum(XAsInteger,YAsInteger)AsIntegerDimTAsIntegerT=X+Ysum=TEndFunctionPrivateSubCommand5_Click()DimaAsInteger,bAsIntegera=InputBox("數(shù)1")b=InputBox("數(shù)2")Printsum(s(a,b),10)EndSub8Functions(ParamArraya()AsVariant)AsSingleDimI,sumAsInteger,CAsIntegerForEachIInasum=sum+IC=C+1Nexts=sum/CEndFunctionPrivateSubCh(ByRefaAsInteger,ByRefbAsInteger)DimTAsIntegerT=a:a=b:b=TPrint"a="&a,"b="&bEndSubPrivateSubCommand1_Click()DimXAsInteger,YAsIntegerX=10:Y=20Print"x="&X,"y="&YCallCh(X,Y)Print"x="&X,"y="&YEndSubPrivateSubCommand2_Click()Printp(10,4),p(3,2),p(10)EndSubPrivateFunctionp(aAsSingle,OptionalNAsInteger=2)AsSinglep=a^NEndFunctionFunctionV(aAsSingle,OptionalbAsVariant,_OptionalCAsVariant)AsSingleIfIsMissing(b)AndIsMissing(C)ThenV=a^3ElseIfIsMissing(C)=TrueThenV=a^2*bElseV=a*b*CEndIfEndFunction9兔子數(shù)列Functionfib(NAsInteger)AsSingleDimf()AsSingleDimIAsIntegerIfN=1OrN=2Thenfib=1ElseReDimf(1ToN)f(1)=1f(2)=1ForI=3ToNf(I)=f(I-1)+f(I-2)NextIfib=f(N)EndIfEndFunctionPrivateSubCommand1_Click()DimjAsIntegerForj=1To20Printfib(j),IfjMod5=0ThenPrintEndIfNextEndSub運(yùn)算PrivateFunctioncal(aAsSingle,sAsString,bAsSingle)AsSingleDimTAsSingleSelectCasesCase"+"T=a+bCase"-"T=a-bCase"*"T=a*bCase"/"Ifb=0ThenMsgBox"除零了"cal=0ExitFunctionElseT=a/bEndIfEndSelectcal=TEndFunctionPrivateSubCommand2_Click()Printcal(10,"/",0)EndSub素?cái)?shù)判定Functionsu(NAsInteger)AsBooleanDimIAsIntegerIfN<=0ThenMsgBoxN&"不會(huì)判別"'ExitFunctionElseIfN<=3Thensu=TrueElseForI=2ToSqr(N)IfNModI=0Thensu=FalseExitForEndIfNextIEndIfEndFunctionPrivateSubCommand3_Click()Printsu(10),su(1)Printsu(-13)EndSubPrivateSubCommand4_Click()RandomizePrintChr(Int(Rnd*26+65))EndSubPrivateSubCommand5_Click()DimsAsStrings=T1.TextT2.Text=sEndSubPrivateSubCommand6_Click()DimaAsIntegerDimbAsIntegerDimTAsIntegera=Val(T1.Text)b=Val(T2.Text)T=a+bT3.Text=TEndSubPrivateSubT1_KeyPress(KeyAsciiAsInteger)IfKeyAscii=vbKeyReturnThenT2.SetFocusEndIfEndSubPrivateSubT2_KeyPress(KeyAsciiAsInteger)IfKeyAscii=vbKeyReturnThenCommand6_Click'Command6_ClickEndIfEndSub10輸入密碼PrivateSubCommand1_Click()StaticCAsIntegerC=C+1IfT.Text="duan"ThenForm4.ShowUnloadMeElseIfC<3ThenIfMsgBox("密碼錯(cuò)誤,繼續(xù)嗎?",_vbQuestion+vbYesNo)=vbYesThenT.Text=""T.SetFocusElseEndEndIfElseMsgBox"您ByeBye吧",vbInformationEndEndIfEndIfEndSubPrivateSubCommand2_Click()EndEndSubPrivateSubT_KeyPress(KeyAsciiAsInteger)IfKeyAscii=13ThenCommand1_ClickEndSub11PrivateSubCommand3_Click()Frame1.Visible=NotFrame1.VisibleFrame2.Visible=NotFrame2.VisibleEndSub12OptionExplicitDimCAsIntegerFunctioncha(aAsInteger,bAsInteger)_AsIntegercha=a-bEndFunction素?cái)?shù)Functionsu(NAsInteger)AsBooleanDimIAsIntegerDimkAsIntegerk=Sqr(N)ForI=2TokIfNModI=0ThenExitForEndIfNextIIfI>kThensu=TrueElsesu=FalseEndIfEndFunction足球守門員隊(duì)員PrivateSubCh_Click(IndexAsInteger)IfCh(Index).Value=1ThenC=C+1ElseC=C-1EndIfIfC>4ThenMsgBox"多了"Ch(Index).Value=0EndIfEndSubPrivateSubCommand1_Click()DimIAsIntegerDimsAsStrings="守門員:"ForI=0To4IfOp(I).Value=TrueThens=s&Op(I).CaptionEndIfNextIs=s&Chr(13)&"隊(duì)員:"ForI=0To8IfCh(I).Value=1Thens=s&Ch(I).Caption&""EndIfNextIIfC=4ThenMsgBoxsElseMsgBox"少了"EndIf'Printer.PrintsEndSub13選擇PrivateSubCommand1_Click()DimsAsStringDimIAsIntegerDimcfAsBooleanIfL1.ListIndex>-1Thens=L1.List(L1.ListIndex)ForI=0ToL2.ListCount-1Ifs=L2.List(I)Thencf=TrueExitForEndIfNextIIfcf=FalseThenL2.AddItemsEndIf'L1.RemoveItemL1.ListIndexEndIfEndSubPrivateSubCommand2_Click()DimIAsIntegerForI=0ToL1.ListCount-1L2.AddItemL1.List(I)NextIL1.ClearEndSub14組合框PrivateSubCommand1_Click()DimIAsIntegerDimcfAsBooleanForI=0ToC.ListCount-1IfC.Text=C.List(I)Thencf=TrueExitForEndIfNextIIfcf=FalseThenC.AddItemC.TextEndIfEndSub15列表框到組合框PrivateSubCommand1_Click()DimIAsIntegerForI=0ToL1.ListCount-1IfL1.Selected(I)ThenL2.AddItemL1.List(I)EndIfNextForI=L1.ListCount-1To0IfL1.Selected(I)ThenL1.RemoveItemIEndIfNextEndSub16滾動(dòng)條PrivateSubForm_Load()T.Text="1.5"EndSubPrivateSubH_Change()T.Text=H.Value/10L.Caption=Val(T1.Text)*H.Value/10EndSubPrivateSubH_Scroll()T.Text=H.Value/10L.Caption=Val(T1.Text)*H.Value/10EndSub17選擇PrivateSubCommand1_Click()DimIAsIntegerForI=0ToL1.ListCount-1IfL1.Selected(I)ThenL2.AddItemL1.List(I)EndIfNextForI=L1.ListCount-1To0IfL1.Selected(I)ThenL1.RemoveItemIEndIfNextEndSub18時(shí)間出現(xiàn)OptionExplicitPrivateSubT_Timer()RandomizeL.ForeColor=RGB(Rnd*255,Rnd*255,Rnd*255)L.Caption=TimeL.Left=L.Left+100IfL.Left>=Me.ScaleWidthThenL.Left=-L.WidthEndIfEndSub19掉字母OptionExplicitDimdAsInteger,CAsIntegerSubcs()RandomizeL.Left=Rnd*(Me.ScaleWidth-L.Width)L.Top=-L.HeightL.Caption=zimuEndSubPrivateFunctionzimu()RandomizeDimkAsIntegerDok=Int(Rnd*58+65)LoopWhilek>90Andk<97zimu=Chr(k)EndFunctionPrivateSubCommand1_Click()Timer1.Interval=200csEndSubPrivateSubCommand2_Click()Ifd+C=0ThenMsgBox"得分率:0"ElseMsgBox"最后正確率:"&d/(d+C)*100&"%"EndIfTimer1.Interval=0csEndEndSubPrivateSubForm_KeyPress(KeyAsciiAsInteger)IfChr(KeyAscii)=L.CaptionThend=d+1csEndIfEndSubPrivateSubForm_Load()csEndSubPrivateSubTimer1_Timer()L.Top=L.Top+100IfL.Top>=Me.ScaleHeightThenC=C+1csEndIfEndSub21正弦函數(shù)PrivateSubCommand1_Click()Constpi=3.1415926DimXAsSingle,YAsSingleForX=0To2*piStep0.0002Y=Sin(X)Me.PSet(X,Y),vbRedNextXLine(-2,0)-(8,0),vbBlueLine(7.8,0.1)-(8,0),vbBlueLine(7.8,-0.1)-(8,0),vbBlueMe.Line(0,1.5)-(0,-1.5),vbBlueForX=-1To7Line(X,0)-(X,0.1),vbBlueIfX<>0ThenMe.CurrentX=X-0.2Me.CurrentY=-0.1PrintXElseMe.CurrentX=0Me.CurrentY=-0.1Print"(0,0)"EndIfNextEndSub22翻轉(zhuǎn)PrivateSubCommand1_Click()DimXAsSingle,YAsSingleX=P1.ScaleWidthY=P1.ScaleHeightP2.PaintPictureP1.Picture,X,0,-X,Y_,0,0,X,YEndSub23卷簾PrivateSubCommand1_Click()DimIAsIntegerDimjAsIntegerDimkAsLongj=P1.ScaleHeight\200ForI=0TojP2.PaintPictureP1.Picture,0,I*200,P1.ScaleWidth,150,_0,I*200,P1.ScaleWidth,150Fork=0To60000000NextNextIEndSub24畫(huà)圖OptionExplicitDimysAsLongDimxxAsSingleDimyyAsSingleDimgjsAsStringDimxkAsIntegerPrivateSubForm_Load()ys=vbBluePpys.BackColor=ysgjs="筆"xk=1EndSubPrivateSubgj_Click(IndexAsInteger)Ppxk.Visible=FalseSelectCaseIndexCase0gjs="筆"Case1gjs="直線"Ppxk.Visible=TrueCase2gjs="吸管"Case3gjs="橡皮"EndSelectEndSubPrivateSubP1_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)SelectCasegjsCase"橡皮"P1.Line(X-100,Y-100)-(X+100,Y+100),P1.BackColorCase"吸管"ys=P1.Point(X,Y)Ppys.BackColor=ysCase"筆"IfButton=1ThenP1.CurrentX=XP1.CurrentY=YEndIfCase"直線"IfButton=1Thenxx=X:yy=YL.X1=XL.Y1=YL.X2=XL.Y2=YL.Visible=TrueL.BorderColor=ysL.BorderWidth=xkEndIfEndSelectEndSubPrivateSubP1_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)SelectCasegjsCase"橡皮"P1.Line(X-100,Y-100)-(X+100,Y+100),P1.BackColorCase"筆"IfButton=1ThenP1.Line-(X,Y),ysEndIfCase"直線"IfButton=1ThenL.X2=XL.Y2=YEndIfEndSelectEndSubPrivateSubP1_MouseUp(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)DimaAsIntegerSelectCasegjsCase"直線"IfButton=1Thena=P1.DrawWidthP1.DrawWidth=xkP1.Line(xx,yy)-(X,Y),ysL.Visible=FalseP1.DrawWidth=aEndIfEndSelectEndSubPrivateSubPxk_Click(IndexAsInteger)xk=Line1(Index).BorderWidthEndSubPrivateSubPys_Click(IndexAsInteger)ys=Pys(Index).BackColorPpys.BackColor=ysEndSub《VB程序設(shè)計(jì)》考試試卷(A)考試形式:閉卷考試考試時(shí)間:120分鐘所有答案答在答題紙上院系學(xué)號(hào)姓名得分題號(hào)一二三四五總分一.判斷題(正確劃√,錯(cuò)誤劃×)(10分)方法的實(shí)質(zhì)是程序代碼模塊√MDI和SDI窗體支持相同的事件和方法程序運(yùn)行中通過(guò)代碼改變單選按鈕的Value值是不會(huì)觸發(fā)該控件的單擊事件的若某子窗體擁有菜單,程序運(yùn)行時(shí)一旦它獲取焦點(diǎn)就會(huì)自動(dòng)覆蓋父窗口的菜單利用通用對(duì)話框控件可以直接完成圖形文件的保存或打開(kāi)操作,無(wú)法直接完成文本文件的保存或打開(kāi)操作由一個(gè)父窗口和多個(gè)子窗口構(gòu)成的應(yīng)用程序,關(guān)閉父窗口就可以終止程序運(yùn)行√若窗口的Enabled屬性為False,其上的控件也不再響應(yīng)鼠標(biāo)事件了?!炭丶?shù)組中的元素可以由不同類型的控件構(gòu)成Me.ForeColor=vbWhite與Me.ForeColor=RGB(0,0,0)等價(jià)AutoRedraw屬性是窗體獨(dú)有的屬性二.單項(xiàng)選擇填空題(共40分)按Delete鍵在TextBox控件中刪除文本時(shí)下列那個(gè)事件不會(huì)觸發(fā)【】A.ChangeB.KeyDownC.KeyUpD.KeyPress下列控件中有Text屬性的是【】A.滾動(dòng)條B.ImageC.組合框D.Frame下列控件中無(wú)value屬性的是【】A.CheckBoxB.OptionButtonC.ScrollBarD.ListBox下列控件中無(wú)Caption屬性的是【】A.LabelB.FrameC.CommandButtonD.Timer對(duì)于一個(gè)正常顯示的窗口來(lái)說(shuō)下列【】事件是最后發(fā)生的A.UnloadB.QueryUnloadC.TerminateD.LostFocus下面【】方法可以直接使組合框控件具有輸入焦點(diǎn)A.SetFocusB.RemoveItemC.RefreshD.AddItem在列表框L中刪除第二條列表?xiàng)l目的值應(yīng)使用【】語(yǔ)句A.L.RemoveItem2B.L.RemoveItemC.L.RemoveItem1D.L.RemoveItem0下列【】語(yǔ)句可以完成隨機(jī)文件的寫(xiě)操作A.PutB.WriteC.GetD.Print若要處理程序運(yùn)行過(guò)程中的錯(cuò)誤應(yīng)使用【】語(yǔ)句先捕獲錯(cuò)誤A.OnErrorGoTo0B.OnErrorResumeNextC.OnErrorGoTo語(yǔ)句行號(hào)D.ResumeNext在VB中保存一個(gè)圖形、圖像文件應(yīng)使用【】。A.PictureSaveB.SavePictureC.LoadPictureD.PictureLoadTimer控件的【】屬性不為0時(shí)可以激發(fā)Timer事件A.EnabledB.IntervalC.VisibleD.Tag一個(gè)控件可以正常接收和處理事件必須保證Visible和【】屬性同時(shí)為真A.EnabledB.FocusC.MoveableD.AppearanceCircle語(yǔ)句不能繪制【】A.扇B.弧C.橢圓D.圓角正方形-若要隱藏某窗體應(yīng)使用【】A.me.HideB.Me.Appearance=FalseC.Me.BorderStyle=NoneD.Me.WindowState=0若要使窗體先于其上控件獲取鍵盤輸入,應(yīng)將窗體的【】設(shè)置為TrueA.AutoRedrawB.MDIChildC.AutoSizeD.KeyPreview應(yīng)使用【】屬性為文本框設(shè)置掩碼A.PasswordCharB.MultiLineC.MaxLengthD.Font設(shè)置【】屬性可使文本框接收多行文字A.ScrollBarsB.MultiLineC.MaxLengthD.Width【】屬性標(biāo)記列表框中列表?xiàng)l目的數(shù)目A.SelCountB.ListCountC.CountD.List下列【】屬性不是只讀屬性A.SelCountB.ListCountC.CurrentXD.AddItem若要使SDI窗體成為子窗體,應(yīng)將窗體的【】屬性設(shè)置為TrueA.BorderStyleB.MDIChildC.AppearanceD.Moveable三.閱讀下面程序,寫(xiě)出單擊Command1后的程序運(yùn)行結(jié)果(10分)Functions(ParamArraya())AsIntegerDimcAsInteger,mAsIntegerDi
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度石油化工設(shè)備采購(gòu)合同補(bǔ)充協(xié)議范本3篇
- 二零二五年度vi設(shè)計(jì)創(chuàng)意制作合同范本2篇
- 二零二五版環(huán)境安全風(fēng)險(xiǎn)評(píng)估與治理合同3篇
- 合同管理在2025年度招投標(biāo)中的合規(guī)性分析3篇
- 二零二五版企業(yè)內(nèi)部技術(shù)人員掛靠合作合同范本3篇
- 二零二五年度高壓電氣設(shè)備采購(gòu)及安裝合同2篇
- 二零二五版寶鋼集團(tuán)勞動(dòng)合同員工加班費(fèi)及休息日工作安排3篇
- 二零二五年度車輛質(zhì)押擔(dān)保合同樣本2篇
- 二零二五版公路貨運(yùn)合同道路運(yùn)輸許可證管理與審查規(guī)范3篇
- 二零二五年度綠色環(huán)保房地產(chǎn)商品房買賣合同書(shū)3篇
- 10日益重要的國(guó)際組織第三課時(shí)中國(guó)與國(guó)際組織(教學(xué)設(shè)計(jì))2023-2024學(xué)年統(tǒng)編版道德與法治六年級(jí)下冊(cè)
- Unit 1 同步練習(xí)人教版2024七年級(jí)英語(yǔ)上冊(cè)
- 工程管理重大風(fēng)險(xiǎn)應(yīng)對(duì)方案
- 直播帶貨助農(nóng)現(xiàn)狀及發(fā)展對(duì)策研究-以抖音直播為例(開(kāi)題)
- 腰椎間盤突出疑難病例討論
- 《光伏發(fā)電工程工程量清單計(jì)價(jià)規(guī)范》
- 2023-2024學(xué)年度人教版四年級(jí)語(yǔ)文上冊(cè)寒假作業(yè)
- (完整版)保證藥品信息來(lái)源合法、真實(shí)、安全的管理措施、情況說(shuō)明及相關(guān)證明
- 營(yíng)銷專員績(jī)效考核指標(biāo)
- 陜西麟游風(fēng)電吊裝方案專家論證版
- 供應(yīng)商審核培訓(xùn)教程
評(píng)論
0/150
提交評(píng)論