資源描述:
《VB編程常用代碼 大一練習(xí)專用》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、A,B,C排序由大到小Dim?a?As?Single,?b?As?Single,?c?As?Singlea?=?Val(Text1.Text)b?=?Val(Text2.Text)c?=?Val(Text3.Text)If?b?>?a?Then?d?=?a:?a?=?b:?b?=?dEnd?IfIf?c?>?a?Then?d?=?a:?a?=?c:?c?=?dEnd?IfIf?c?>?b?Then?d?=?b:?b?=?c:?c?=?dEnd?IfText4.Text?=?aText5.Text?=?bText6.Text?=?cEnd?SubPrivate?Sub?Comma
2、nd2_Click()Text1.Text?=?""Text2.Text?=?""Text3.Text?=?""Text4.Text?=?""Text5.Text?=?""Text6.Text?=?""End?Sub計(jì)算a+bPrivateSubCommand1_Click()Text4.Text=Val(Text2.Text)+Val(Text3.Text)Text1.Text="歡迎新同學(xué)"EndSub清除PrivateSubCommand2_Click()Text1.Text=""Text2.Text=""Text3.Text=""Text4.Text=""EndSub奇
3、偶數(shù)顯示器顯示PrivateSubCommand1_Click()DimaAsIntegera=Val(Text1.Text)Ifa/2=Int(a/2)ThenText2.Text="您輸入的數(shù)是偶數(shù)"ElseText2.Text="您輸入的數(shù)是奇數(shù)"EndIfEndSub清除PrivateSubCommand2_Click()Text1.Text=""Text2.Text=""EndSub奇偶數(shù)判斷Dima,bAsIntegerDimresultAsIntegera=Val(InputBox("請(qǐng)輸入一個(gè)整數(shù)","數(shù)的輸入",300,400))b=Val(InputBox(
4、"請(qǐng)輸入一個(gè)整數(shù)","數(shù)的輸入",300,400))Ifa/2=Int(a/2)Thenresult=MsgBox("您輸入的數(shù):"&a&"是一個(gè)偶數(shù)",1,"判斷結(jié)果")Form1.PrintrusultElsem="您輸入的數(shù):"&a&"是一個(gè)奇數(shù)"result=MsgBox("您輸入的數(shù):"&a&"是一個(gè)奇數(shù)",1,"判斷結(jié)果")Form1.PrintresultEndIfIfb/2=Int(b/2)Thenresult=MsgBox("您輸入的數(shù):"&b&"是一個(gè)偶數(shù)",1,"判斷結(jié)果")Form1.PrintrusultElseresult=MsgBox("您輸入的數(shù)
5、:"&b&"是一個(gè)奇數(shù)",1,"判斷結(jié)果")Form1.PrintresultEndIf奇偶數(shù)判斷PrivateSubCommand1_Click()Dima,bAsInteger'變量聲明DimresultAsInteger'結(jié)果設(shè)為整形(數(shù)值型)a=Val(InputBox("請(qǐng)輸入一個(gè)數(shù)","數(shù)的輸入",200,300))'變量賦值(提示語(yǔ),標(biāo)題,返回值顯示坐標(biāo))b=Val(InputBox("請(qǐng)輸入一個(gè)數(shù)","數(shù)的輸入",200,300))Ifa/2=Int(a/2)Then'關(guān)系判斷n="你輸出的數(shù);"&a&"是偶數(shù)"'結(jié)果輸出result=MsgBox(n,1,"判
6、斷結(jié)果為")'(提示語(yǔ),按鈕設(shè)置值,標(biāo)題)Form1.PrintresultElsen="你輸出的數(shù):"&a&"是奇數(shù)"'結(jié)果輸出result=MsgBox(n,1,"判斷結(jié)果為")Form1.PrintresultEndIfIfb/2=Int(b/2)Thenm="你輸出的數(shù);"&b&"是偶數(shù)"'出錯(cuò)點(diǎn):“&”和“=”處打空格提示語(yǔ)與標(biāo)題的設(shè)置為文本型加引號(hào)'英文的冒號(hào)與分號(hào)運(yùn)用result=MsgBox(m,1,"判斷結(jié)果為")Form1.PrintresultElsem="你輸出的數(shù):"&b&"是奇數(shù)"result=MsgBox(m,1,"判斷結(jié)果為")Form1.Pri
7、ntresultEndIfEndSub1.設(shè)計(jì)程序計(jì)算圓的周長(zhǎng)和面積
2.用print方法輸出一個(gè)空心圖形:如正方形,長(zhǎng)方形,三角形,平行四邊形。
3.一個(gè)籠子里雞和兔,一共數(shù)得h個(gè)頭、f只腳。設(shè)計(jì)程序計(jì)算雞和兔共有幾只。
privatesubForm_lond()Debug.Print5+7ClsCaption="用方print法輸出"AutoRedraw=TruePrintFori=1To5PrintTab(15-i);String(i,"●");Tab(30-i);String(i,"