vb實驗指導答案_第1頁
vb實驗指導答案_第2頁
vb實驗指導答案_第3頁
vb實驗指導答案_第4頁
vb實驗指導答案_第5頁
已閱讀5頁,還剩14頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

實驗一2.PrivateSubCommand1_Click()Label1.ForeColor=vbRedEndSubPrivateSubCommand2_Click()Label1.BackColor=vbBlueEndSubPrivateSubCommand3_Click()Label1.ForeColor=Form1.ForeColorLabel1.BackColor=Form1.BackColorEndSubPrivateSubCommand4_Click()EndEndSub3.PrivateSubCommand1_Click()Text1.FontSize=30Command1.Enabled=FalseCommand2.Enabled=TrueCommand3.Enabled=TrueEndSubPrivateSubCommand2_Click()Text1.FontSize=6Command2.Enabled=FalseCommand1.Enabled=TrueCommand3.Enabled=TrueEndSubPrivateSubCommand3_Click()Text1.FontSize=9Command3.Enabled=FalseCommand1.Enabled=TrueCommand2.Enabled=TrueEndSub4.PrivateSubCommand1_Click()a=3.14r=Val(Text1.Text)Text2.Text=2*a*rText3.Text=a*r*rEndSubPrivateSubCommand2_Click()Text1.Text=""Text2.Text=""Text3.Text=""EndSubPrivateSubCommand3_Click()EndEndSub5.PrivateSubCommand1_Click()Label1.BorderStyle=1EndSubPrivateSubCommand2_Click()Label1.Left=Label1.Left+200Label1.Top=Label1.Top-150EndSubPrivateSubCommand3_Click()Label1.Visible=FalseEndSubPrivateSubCommand4_Click()Label1.Visible=TrueEndSub6.PrivateSubCommand1_Click()Text2.Text=Text1.SelTextText3.Text=Text1.SelLengthText1.Locked=TrueEndSubPrivateSubCommand2_Click()Text1.Text=""Text2.Text=""Text3.Text=""Text1.SetFocusEndSub7.PrivateSubCommand1_Click()Dimr,q,vq=Val(Text2.Text)r=Val(Text1.Text)v=Val(Text3.Text)Label5.Caption=r*60*60+q*60+vEndSubPrivateSubCommand2_Click()Text1.Text=""Text2.Text=""Text3.Text=""Text1.SetFocusText2.SetFocusText3.SetFocusEndSubPrivateSubCommand3_Click()EndEndSubPrivateSubText1_keypress(keyasciiAsInteger)Ifkeyascii=13ThenText2.SetFocusEndSubPrivateSubText2_keypress(keyasciiAsInteger)Ifkeyascii=13ThenText3.SetFocusEndSub8.(1)Dima,v,s,cPrivateSubText1_KeyPress(KeyAsciiAsInteger)a=Val(Text1.Text)IfKeyAscii=13Thenv=a*a*as=6*a*ac=4*aLabel5.Caption=vLabel6.Caption=sText2.Text=cEndIfEndSub(2)Dima,s,v,cPrivateSubText1_LostFocus()a=Val(Text1.Text)c=12*av=a*a*as=6*a*ac=Val(Text2.Text)Label5.Caption=vLabel6.Caption=sEndSub(3)Dima,v,s,cPrivateSubText1_Change()a=Val(Text1.Text)v=a*a*as=6*a*ac=12*aLabel5.Caption=vLabel6.Caption=sText2.Text=cEndSub實驗二2.PrivateSubPicture1_Click()a=Int(Val(Text1.Text)/100)b=Int((Val(Text1.Text)Mod100)/10)c=Int((Val(Text1.Text)Mod100)Mod10)d=a*a+b*b+c*cPicture1.Printa;b;c;dEndSub3.PrivateSubCommand1_Click()a=Val(Text1.Text)b=Val(Text2.Text)s=a/bText3.Text=Format(s,"###.##")Text4.Text=a\bText5.Text=aModbEndSubPrivateSubCommand2_Click()Text1.Text=""Text2.Text=""Text3.Text=""Text4.Text=""Text5.Text=""Text1.SetFocusEndSubPrivateSubCommand3_Click()EndEndSub4.PrivateSubCommand1_Click()a=Val(Text1.Text)b=Val(Text2.Text)Picture1.PrintInt(Rnd*(b-a+1)+a);Picture1.PrintInt(Rnd*(b-a+1)+a);Picture1.PrintInt(Rnd*(b-a+1)+a)t1=Int(Rnd*(b-a+1)+a)t2=Int(Rnd*(b-a+1)+a)t3=Int(Rnd*(b-a+1)+a)s=Sqr(t1+t2+t3)f=Format(s,"##.####")Picture1.Print"三個數(shù)和的平方根"&"="&fEndSubPrivateSubCommand2_Click()Text1.Text=""Text2.Text=""Text1.SetFocusEndSubPrivateSubCommand3_Click()EndEndSub5.PrivateSubForm_Load()Text1.Text=""Text2.Text=""EndSubPrivateSubText2_KeyPress(KeyAsciiAsInteger)Dimi,xIfKeyAscii=13ThenIfLen(Text1)>25Theni=InStr(Text1,Text2)x=Left(Text1,i-1)+Mid(Text1,i+Len(Text2))EndIfEndIfPicture1.PrintxEndSub6.PrivateSubCommand1_Click()RandomizeText1.FontSize=Text1.FontSize*Int(Rnd*3+2)Command1.Enabled=FalseCommand2.Enabled=TrueCommand3.Enabled=TrueEndSubPrivateSubCommand2_Click()RandomizeText1.FontSize=Text1.FontSize/Int(Rnd*3+2)Command1.Enabled=TrueCommand2.Enabled=FalseCommand3.Enabled=TrueEndSubPrivateSubCommand3_Click()Text1.FontSize=9Command1.Enabled=TrueCommand2.Enabled=TrueCommand3.Enabled=FalseEndSub實驗三2.PrivateSubForm_Click()FontItalic=TruePrint"斜體→程序設計語言"FontName="黑體"Print"黑體→程序設計語言"FontName="幼圓"Print"幼圓→程序設計語言"FontName="楷體_gb2312"Print"楷體→程序設計語言"FontName="隸書"Print"隸書→程序設計語言"FontName="@宋體"Print"設置宋體字體旋轉(zhuǎn)"EndSub3.PrivateSubCommand1_Click()Dima&,day&,hour&,minute&,second&a=Val(Text1.Text)day=Int(a\86400)hour=Int((aMod86400)\3600)minute=Int((aMod3600)\60)second=Int(aMod60)Picture1.Printa&;"秒"&"="&day&;"天"&hour&;"小時"&minute&;"分"&second;"秒"EndSub4.PrivateSubCommand1_Click()r=InputBox("輸入圓半徑")Text1.Text=rLabel5.Caption=3.14*r*rLabel6.Caption=4*3.14*r*rLabel7.Caption=4/3*3.14*r*r*rEndSubPrivateSubCommand2_Click()Label5.Caption=""Label6.Caption=""Label7.Caption=""Text1.SetFocusText1.Text=""EndSub6.PrivateSubCommand1_Click()DimH%,F%,X%,Y%H=Val(Text1.Text)F=Val(Text2.Text)X=(4*H-F)/2Y=(F-2*H)/2Picture1.Print"雞的數(shù)量";XPicture1.Print"兔子的數(shù)量";YEndSubPrivateSubCommand2_Click()Label3.Caption=""Text1.Text=""Text2.Text=""Text1.SetFocusEndSub7.PrivateSubForm_Load()Text1.Text=""Text2.Text=""Label4.Caption=""EndSubPrivateSubText2_KeyPress(KeyAsciiAsInteger)Dimp,dIfKeyAscii=13Thenp=Val(Text1.Text)d=Val(Text2.Text)s=p*dc=s-(s*0.005+s*0.015+s*0.035+27.83)Label4.Caption=Format(c,"####.##")EndIfEndSub實驗四2.PrivateSubCommand1_Click()a=Val(Text1.Text)b=Val(Text2.Text)c=Val(Text3.Text)Ifa+b>cOra+c>bOrb+c>aThenp=(a+b+c)/2s=Sqr(p*(p-a)*(p-b)*(p-c))Label5.Caption=Format(s,"#00.000")ElseMsgBox"不能構(gòu)成三角形"EndIfEndSubPrivateSubCommand2_Click()Text1.Text=""Text2.Text=""Text3.Text=""Label5.Caption=""Text1.SetFocusEndSubPrivateSubCommand3_Click()EndEndSubPrivateSubText1_KeyPress(KeyAsciiAsInteger)IfKeyAscii=13ThenText2.SetFocusEndSubPrivateSubText1_LostFocus()IfNotIsNumeric(Text1.Text)ThenMsgBox"輸入錯誤!重新輸入"Text1.Text=""Text1.SetFocusEndIfEndSubPrivateSubText2_KeyPress(KeyAsciiAsInteger)IfKeyAscii=13ThenText3.SetFocusEndSubPrivateSubText2_LostFocus()IfNotIsNumeric(Text2.Text)ThenMsgBox"輸入錯誤!重新輸入"Text2.Text=""Text2.SetFocusEndIfEndSubPrivateSubText3_LostFocus()IfNotIsNumeric(Text1.Text)ThenMsgBox"輸入錯誤!重新輸入"Text3.Text=""Text3.SetFocusEndIfEndSub3.PrivateSubCommand1_Click()a=Val(Text1.Text)b=Val(Text2.Text)SelectCaseText3.TextCase"+"Text4.Text=a+bCase"-"Text4.Text=a-bCase"*"Text4.Text=a*bCase"/"Ifb=0ThenMsgBox"除數(shù)為零"Text2.Text=""ElseText4.Text=a/bEndIfCase"\"Ifb=0ThenMsgBox"除數(shù)為零"Text2.Text=""ElseText4.Text=a\bEndIfCase"mod"Text4.Text=aModbCase"^"Text4.Text=a^bEndSelectEndSubPrivateSubCommand2_Click()Text1.Text=""Text2.Text=""Text3.Text=""Text4.Text=""Text1.SetFocusEndSubPrivateSubCommand3_Click()EndEndSubPrivateSubForm_Load()Text1.Text=""Text2.Text=""Text3.Text=""Text4.Text=""EndSubPrivateSubText1_LostFocus()IfNotIsNumeric(Text1.Text)ThenMsgBox"輸入出錯!重新輸入"Text1.Text=""Text1.SetFocusEndIfEndSubPrivateSubText2_LostFocus()IfNotIsNumeric(Text2.Text)ThenMsgBox"輸入錯誤!重新輸入"Text2.Text=""Text2.SetFocusEndIfEndSub6.PrivateSubText1_LostFocus()IfNotIsNumeric(Text1.Text)ThenMsgBox"不是數(shù)字,重新輸入!"Text1.Text=""Text1.SetFocusEndIfEndSubPrivateSubText2_LostFocus()IfNotIsNumeric(Text2.Text)ThenMsgBox"不是數(shù)字,重新輸入!"Text2.Text=""Text2.SetFocusEndIfEndSubPrivateSubText3_LostFocus()IfNotIsNumeric(Text3.Text)ThenMsgBox"不是數(shù)字,重新輸入!"Text3.Text=""Text3.SetFocusEndIfEndSubPrivateSubForm_Load()Text1.Text=""Text2.Text=""Text3.Text=""EndSubPrivateSubText3_KeyPress(KeyAsciiAsInteger)IfKeyAscii=13ThenDima(0To2)AsIntegera(0)=InputBox("輸入第一個數(shù)字",輸入,0)a(1)=InputBox("輸入第二個數(shù)字",輸入,0)a(2)=InputBox("輸入第三個數(shù)字",輸入,0)Forj=1To2Fori=0To2-jIfa(i)<a(i+1)Thent=a(i):a(i)=a(i+1):a(i+1)=tNextiNextjPicture1.Printa(0);">";a(1);">";a(2)EndIfEndSub7.PrivateSubCommand1_Click()DimaAsIntegera=Val(Text1.Text)If(aMod400)=0ThenLabel3.Caption="是閏年"ElseLabel3.Caption="不是閏年"EndIfSelectCaseText2.TextCase1,3,5,7,8,10,12Label5.Caption=31Case2If(aMod400)=0ThenLabel5.Caption=28ElseLabel5.Caption=29EndIfCase4,6,9,11Label5.Caption=30EndSelectSelectCaseText2.TextCase12,1,2Label4.Caption="冬季"Case3,4,5Label4.Caption="春季"Case6,7,8Label4.Caption="夏季"Case9,10,11Label4.Caption="秋季"EndSelectEndSubPrivateSubCommand2_Click()Text1.Text=""Text2.Text=""Picture1.ClsPicture2.ClsPicture3.ClsText1.SetFocusEndSub8.PrivateSubForm_Click()a=Val(InputBox("M1"))b=Val(InputBox("M2"))c=Val(InputBox("M3"))d=(a+b+c)/3Ifd>95ThenPrint"一等獎"EndIfIfa=100Andb=100Andc>=80Ora=100Andc=100Andb>=80Orc=100Andb=100Anda>=80ThenPrint"一等獎"EndIfIfd>90ThenPrint"二等獎"EndIfIfa=100Andb>=75Andc>=75Orb=100Andc>=75Andb>=75Orc=100Andb>=75Anda>=75ThenPrint"二等獎"EndIfIfa>=70Andb>=70Andc>=70ThenPrint"三等獎"EndIfEndSub實驗五2.PrivateSubPicture1_Click()Forn=2To1000Ifn=n^2Mod10ThenPicture1.PrintnIfn=n^2Mod100ThenPicture1.PrintnIfn=n^2Mod1000ThenPicture1.PrintnNextnEndSub3.PrivateSubCommand1_Click()Dimn%,s$,tAsStrings=0n=0Forx=10To10000IfxMod3=2OrxMod5=3OrxMod7=2Thent=t&x&vbCrLfn=n+1s=s+xEndIfNextxText1.Text=tPicture1.Print"數(shù)的和"&sPicture1.Print"數(shù)的個數(shù)"&nEndSubPrivateSubCommand2_Click()Dimn%,s$,tAsStrings=0n=0x=10DoWhilex<10000IfxMod3=2OrxMod5=3OrxMod7=2Thent=t&x&vbCrLfn=n+1s=s+xEndIfx=x+1LoopText1.Text=tPicture1.Print"數(shù)的和"&sPicture1.Print"數(shù)的個數(shù)"&nEndSub5.PrivateSubPicture1_Click()Dimn%,s%n=Val(InputBox("n值"))s=0Fori=1Tons=s+i^2NextPicture1.PrintsEndSubPrivateSubPicture2_Click()DimnAsIntegern=Val(InputBox("輸入n值"))sum=0Dima1AsDoubleDima2AsDoubleDimaAsDoubleDimsumAsDoublea1=1a2=1Fori=1Tont=a1+a2a1=a2a2=ta=a2/a1sum=sum+aNextiPicture2.PrintsumEndSubPrivateSubPicture3_Click()Dimn%,s%n=Val(InputBox("n值"))s=0a1=1a2=1Fori=1Tont=a1*a2NextiPicture3.PrintsEndSubPrivateSubPicture4_Click()Dimi,nAsInteger,sAsDoublen=Val(InputBox("n值"))Ifn>=1ThenFori=1Tont=5*10^na=t+5*10^ns=s+tNextiPicture4.PrintsEndIfEndSubPrivateSubPicture5_Click()Dimi,nAsIntegerDimsAsSinglen=Val(InputBox("n值"))Fori=1Tons=s+(-1)^(i+1)*(1/i)Nextit=Format(s,"##0.#######")Picture5.PrinttEndSub8.PrivateSubCommand2_Click()Picture1.ClsEndSubPrivateSubCommand1_Click()Forn=6To1000k=0Forx=1Ton/2IfnModx=0Thenk=k+xEndIfNextxIfk=nThenPicture1.PrintkEndIfNextnEndSub10.PrivateSubForm_Click()Fori=1To9Fora=1ToiPrintTab(20-i);NextForn=1ToiPrintTrim(n);NextFors=n-2To1Step-1PrintTrim(s);NextPrintNextEndSub實驗六2.PrivateSubForm_Click()Dima(100)RandomizeMax=20Min=100s=0n=0Fori=1To100a(i)=Int(Rnd*81+20)Picture1.Printa(i);Ifi/10=i\10ThenPicture1.PrintIfa(i)>MaxThenMax=a(i)Ifa(i)<MinThenMin=a(i)s=s+a(i)Nextiv=Format(s/100,"##0.###")Fori=1To100Ifa(i)>(s/100)Thenn=n+1NextLabel1.Caption="max="&Max&vbCrLf&"min="&Min&vbCrLf&"平均值為"&v&vbCrLf&"大于平均值的元素個數(shù)為"&nEndSub3.PrivateSubCommand1_Click()Dima(),b()AsVariant,c()AsSinglea=Array(2,8,7,6,4,28,70,25)b=Array(79,27,32,41,57,66,78,80)Print"第一個數(shù)組為:"&vbCrLfFori=LBound(a)ToUBound(a)Printa(i);NextiPrintPrint"第二個數(shù)組為:"&vbCrLfFori=LBound(a)ToUBound(a)Printb(i);NextiReDimc(UBound(a))PrintPrint"兩個數(shù)組相對元素相加的結(jié)果為:"&vbCrLfFori=LBound(a)ToUBound(a)c(i)=a(i)+b(i)Printc(i);NextiPrintFori=LBound(a)ToUBound(a)-1Forj=LBound(a)ToUBound(a)-1-iIfc(j)<c(j+1)Thent=c(j)c(j)=c(j+1)c(j+1)=tEndIfNextNextPrintPrint"相加的結(jié)果的降序為:"&vbCrLfFori=LBound(a)ToUBound(a)Printc(i);NextEndSub4.PrivateSubForm_Click()Dima(20)RandomizePrint"對換前"&crlfFori=1To20a(i)=Int(Rnd*89+11)Printa(i);Ifi/10=i\10ThenPrintNextiPrintPrint"對換后"&crlfFori=1To10t=a(i):a(i)=a(i+10):a(i+10)=tNextiFori=1To20Printa(i);Ifi/10=i\10ThenPrintNextiEndSub6.PrivateSubPicture1_Click()n=Val(Text1.Text)ReDima(n+1,n+1),b(n+1,n+1)Clsk=8Fori=1TonPicture1.PrintString((n-i)*k/2+1,""

溫馨提示

  • 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

提交評論