VB程序设计教程(第3版)课后实验答案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

实验AA.1PrivateSubCommand1_Click()Label3=Text1EndSubA.2PrivateSubForm_Load()Timer1.Interval=0EndSubPrivateSubCommand1_Click()'自动Timer1.Interval=200EndSubPrivateSubCommand2_Click()'手动Timer1.Interval=0CallMyMoveEndSubPrivateSubTimer1_Timer()CallMyMoveEndSubSubMyMove()Label1.MoveLabel1.Left-50IfLabel1.Left0ThenLabel1.Left=Form1.WidthEndSubA.3PrivateSubForm_Click()Text1=Val(Text1)+1EndSubPrivateSubForm_Load()Text1=0EndSubA.4PrivateSubForm_Click()Caption=单击窗体,改变图片Picture=LoadPicture(App.Path+\n_015.bmp)Print欢迎使用VBEndSubPrivateSubForm_DblClick()ClsCaption=双击窗体,卸去图片Picture=LoadPicture()'EndSubPrivateSubForm_Load()Caption=装入窗体Picture=LoadPicture(App.Path+\n_016.bmp)Print装入图EndSubPrivateSubForm_Resize()'该事件的作用窗体始终与图一样大'Caption=窗体大小不变'Form1.Width=260*16'260是Tongji-2.bmp图的宽度,象素单位'Form1.Height=260*16+200'260是图的高度,象素单位,200是窗体的标题栏高度EndSubA.5SubCommand1_Click()Text1.FontName=隶书Text1.FontSize=25EndSubSubCommand2_Click()Text2.Text=Text1.SelTextText2.FontName=Text1.FontNameText2.FontSize=Text1.FontSizeEndSub实验BB.1PrivateSubCommand1_Click()Text2=Format(5/9*(Val(Text1)-32),0.00)EndSubPrivateSubCommand2_Click()Text1=Format(9/5*Val(Text2)+32,0.00)EndSub或PrivateSubCommand1_Click()Dimf!,c!'声明两个变量f=Val(Text1)c=5/9*(f-32)Text2=Format(c,0.00)'保留两位小数EndSubPrivateSubCommand2_Click()Dimff!,cc!'声明两个变量cc=Val(Text2)ff=9/5*cc+32Text1=Format(ff,0.00)'保留两位小数EndSubB.2PrivateSubCommand1_Click()Label2=Format(Val(Text1)*Val(Text1)*3.14,0.00)EndSubPrivateSubCommand2_Click()Label3=Format(Val(Text1)*3.14*2,0.00)EndSubPrivateSubText1_LostFocus()IfNotIsNumeric(Text1.Text)ThenMsgBox输入有非数字字符,请重新输入,,警告Text1.Text=Text1.SetFocusEndIfEndSub或PrivateSubCommand1_Click()Label2=Format(Val(Text1)*Val(Text1)*3.14,0.00)EndSubPrivateSubCommand2_Click()Label3=Format(Val(Text1)*3.14*2,0.00)EndSubPrivateSubText1_KeyPress(KeyAsciiAsInteger)IfKeyAscii=13ThenIfNotIsNumeric(Text1.Text)ThenText1.Text=EndIfEndIfEndSubB.3PrivateSubCommand1_Click()n=Int(Log(2)/Log(1.008)+1)Label1=n&年后人数超过26亿EndSubB.4PrivateSubCommand1_Click()Dimx,dx,cdx=Text1.Textdx=UCase(x)cd=Len(x)Print大写字母为:;dxPrint字符串长度为:;cdEndSubB.5PrivateSubCommand1_Click()Text1=Int(Rnd*900+100)EndSubPrivateSubCommand2_Click()Dimx%,x1%,x2%,x3%x=Val(Text1)x1=xMod10'分离出的个位数x2=(xMod100)\10'分离出的十位数x3=x\100'分离出的百位数Label1=x1*100+x2*10+x3EndSubB.6PrivateSubForm_Click()Label1=Left(Text1,11)Label2=Mid(Text1,12,6)Label3=Right(Text1,5)EndSubB.7PrivateSubCommand1_Click()PrintFori=1To5PrintTab(15-i*2);String(2*i-1,★);Spc(18-4*(i-1));String(2*i-1,★)NextiEndSubPrivateSubCommand2_Click()ClsEndSub进一步要求:PrivateSubCommand1_Click()PrintFori=1To5PrintTab(15-i*2);String(2*i-1,★);String(10-(2*i-1),☆);String(2*i-1,★)NextiEndSubPrivateSubCommand2_Click()ClsEndSubB.8PrivateSubForm_Click()x=Val(InputBox(输入一正实数,计算,0))pf=Format(x*x,0.000)pfg=Format(Sqr(x),0.000)lf=Format(x*x*x,0.000)lfg=Format(x^(1/3),0.000)Print平方为:;pf;Space(5);平方根为:;pfg;Space(5);立方为:;lf;Space(5);立方根为:;lfgEndSub实验CC.1PrivateSubForm_Click()Dimx!,y!x=Val(InputBox(输入x的值))Ifx1000Theny=xElseIfx2000Theny=0.9*xElseIfx3000Theny=0.8*xElsey=0.7*xEndIfPrintyEndSubC.2PrivateSubForm_Click()Dimx!,y!x=Val(InputBox(输入上网时间))Ifx10Theny=30ElseIfx50Theny=30+2.5*(x-10)Elsey=30+2.5*40+2*(x-50)EndIfIfy150Theny=150EndIfPrintyEndSubC.3PrivateSubCommand1_Click()Dimx!,y!,z!x=InputBox(inputx)y=InputBox(inputy)z=InputBox(inputz)PrintxyzPrint排序前;x;;y;;zIfxyThent=x:x=y:y=tIfxzThent=x:x=z:z=tIfyzThent=y:y=z:z=tPrint排序后&x&&y&&zEndSubPrivateSubCommand2_Click()Dimx!,y!,z!x=InputBox(inputx)y=InputBox(inputy)z=InputBox(inputz)PrintxyzPrint排序前;x;;y;;zIfxyThent=x:x=y:y=tIfyzThent=y:y=z:z=tIfxyThent=x:x=y:y=tEndIfEndIfPrint排序后&x&&y&&zEndSubC.4Dima(3)AsIntegerPrivateSubCommand1_Click()Picture1.ClsFori=0To2a(i)=Int(Rnd*100+200)Picture1.Printa(i)NextiEndSubPrivateSubCommand2_Click()Picture2.ClsDimzAsIntegerFori=0To1Ifa(i)a(i+1)Thenz=a(i+1)a(i+1)=a(i)a(i)=zEndIfNextiPicture2.Printa(0)Picture2.Printa(1)Picture2.Printa(2)EndSubC.5PrivateSubText2_LostFocus()Dimm%,n%,y%m=Val(Text1)n=Val(Text2)IfnMod20ThenMsgBox(脚数必定为偶数)Text2=Text2.SetFocusElsey=n/2-mIfy0ThenMsgBox(脚数必须≥2倍的头数,请重新输入)Text2=Text2.SetFocusElsex=n/2-mLabel2=yLabel3=m-yEndIfEndIfEndSubC.6PrivateSubCommand1_Click()Dima!,b!,c!,x1!,x2!,de!a=Text1b=Text2c=Text3de=b*b-4*a*ct=2*aIfde=0ThenText4=Format(-b/t,0.00)Text5=Format(-b/t,0.00)ElseIfde0ThenText4=Format((-b+Sqr(de))/t,0.00)Text5=Format((-b-Sqr(de))/t,0.00)ElseText4=Format(-b/t,0.00)&+&Format(Sqr(Abs(de))/t,0.00)&iText5=Format(-b/t,0.00)&-&Format(Sqr(Abs(de))/t,0.00)&iEndIfEndSubPrivateSubCommand2_Click()Text1=Text2=Text3=Text4=Text5=EndSubC.7PrivateSubText3_LostFocus()SelectCaseTrim(Text3)Case+Text4=Val(Text1)+Val(Text2)Case-Text4=Val(Text1)-Val(Text2)Case*Text4=Val(Text1)*Val(Text2)Case/IfVal(Text2)=0ThenMsgBox分母为零,重新输入Text2=Text2.SetFocusElseText4=Val(Text1)/Val(Text2)EndIfEndSelectEndSubC.8PrivateSubText1_LostFocus()SelectCaseTrim(Text1)Case1Text2=MondayCase2Text2=TuesdayCase3Text2=WednesdayCase4Text2=ThursdayCase5Text2=FridayCase6Text2=SaturdayCase7Text2=SundayCaseIs7,Is1MsgBox数字为1~7,重新输入Text1=Tex

1 / 37
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功