河南大学VB程序设计课后习题参考答案.pdf

上传人:无*** 文档编号:90867776 上传时间:2023-05-18 格式:PDF 页数:46 大小:2.91MB
返回 下载 相关 举报
河南大学VB程序设计课后习题参考答案.pdf_第1页
第1页 / 共46页
河南大学VB程序设计课后习题参考答案.pdf_第2页
第2页 / 共46页
点击查看更多>>
资源描述

《河南大学VB程序设计课后习题参考答案.pdf》由会员分享,可在线阅读,更多相关《河南大学VB程序设计课后习题参考答案.pdf(46页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、河南大学VB程序设计课后习题参考答案(编码)2-1Private Sub Form_Click()CisEnd SubPrivate Sub Form_DblClick()FontSize=40FontName=”隶书”ForeColor=vbRedPrint”热烈庆祝”FontSize=60FontName=宋体ForeColor=vbGreenPrint”河南大学运动会召开”End Sub2-2Private Sub Command1_Click()Label 1.Move Width*Rnd,Height*RndEnd Sub2-3Private Sub Command1_Click()

2、Labell.Visible=TrueEnd SubPrivate Sub Command2_Click()Labell.Visible=FalseEnd Sub2-4Private Sub Timer1_Timer()Textl.Text=NowCaption=Textl.TextEnd Sub2-5Private Sub Timer1_Timer()If BackColor=vbRed ThenBackColor=vbYellowElseBackColor=vbRedEnd IfEnd Sub2-6Private Sub Timeri_Timer()If Labell.Left -Labe

3、ll.Height ThenLabell.Top=Labell.Top-100ElseLabell.Top=Forml.HeightEnd IfEnd Sub3-2Private Sub Form_Click()Dim n As IntegerRandomizen=lnt(90*Rnd)+10)Print nEnd Sub3-3Private Sub Timeri_Timer()CisPrint”河南大学环境与规划学院”FontSize=lnt(71*Rnd+10)End Sub3-4Private Sub Command1_Click()n=Textl.TextText2.Text=Hex(

4、Asc(Right(Text1.Text,1)End SubPrivate Sub Command2_Click()Textl.Text=Text2.Text=”Textl.SetFocusEnd Sub3-5Private Sub Command1_Click()Dim m As Datem=Textl.Textn=DateText2.Text=n-mEnd SubPrivate Sub Command2_Click()Textl.Text=Text2.Text=Textl.SetFocusEnd Sub3-6Dim b As StringDim n As StringDim m As St

5、ringPrivate Sub Command1_Click()m=Left(Text1,1)n=Right(Text1,1)b=Mid(Text1,2,1)Text2.Text=n&b&mEnd SubPrivate Sub Command2_Click()Textl.Text=Text2.Text=Textl.SetFocusEnd Sub3-7Private Sub Form_click()r=InputBox(请输入字符”)Print Left(r,1)&Mid(r,3,1)&Right(r,1)End Sub3-8Private Sub Timer1_Timer()Label 1 .

6、FontSize=Rnd*40+10Labell.BackColor=RGB(Rnd*256,Rnd*256,Rnd*256)Labell.ForeColor=QBColor(lnt(16*Rnd)End Sub3-10Private Sub Form_Click()r!=InputBox(请输入您的工资:)a=r100b=(r-100*a)50c=(r-100*a-b*50)10d=(r-1 0 0*a-b*5 0-c*1 0)5e=(r-100*a-b*50-c*10-d*5)2f=r-1 0 0*a-b*5 0-c*1 0-d*5-e*2Print”您的工资是:“&rPrint”100

7、元张数:n&aPrint”50 元张数:&bPrint”10 元张数:&cPrint”5 元张数:&dPrint”2 元张数:&ePrint 元张数:&fEnd Sub4-1Private Sub Command1_Click()Dim p As Single,r As Single,n As Singlep=Textlr=Text2n=Text3s=p*(1+r)A nMsgBox”您的本息是:&Round(s,2)End Sub4-2Private Sub Form_click()Dim max As Single,min As Singlea!=InputBox(请输入第一个实数”)b!

8、=InputBox(请输入第二个实数”)If a b ThenPrint a,bElsePrint b,aEnd IfEnd Sub4-3Private Sub Form_click()Cisa!=InputBox(请输入年份)If a Mod 4=0 And a Mod 100 0&a Mod 400=0ThenPrint”您刚刚输入的年份为闰年!”ElsePrint”您刚刚输入的年份不是闰年!”End IfEnd Sub4-4Private Sub Form_click()a!=lnputBox(a=H)b!=lnputBox(b=)c!=lnputBox(“c=)d!=b*b-4*a*c

9、If d=0 Thenm!=(-b+Sqr(d)/(2*a)n!=(-b-Sqr(d)/(2*a)Print”X1=;m,”X2=;nElser=(-b)/(2*a)i=Sqr(Abs(-d)/(2*a)Print X1=n;r&Abs(i)&i“,”二 X2=n;r&Abs(i)&i”End IfEnd Sub4-5Private Sub Command1_Click()Dim x!x=TextlIf x 60 ThenText2=重考!”Elself x 70 ThenText2=及格!Elself x 80 ThenText2=中等!”Elself x 90 ThenText2=良好!”

10、ElseText2=”优秀!”End IfEnd SubPrivate Sub Command2_Click()Textl=Text2=H,End Sub4-6Private Sub Command1_Click()Dim x!x=TextlSelect Case xCase Is 60Text2=重考!Case Is 70Text2=及格!”Case Is 80Text2=中等!”Case Is 90Text2=良好!Case ElseText2=”优秀!”End SelectEnd SubPrivate Sub Command2_Click()Textl=Text2=End Sub4-7D

11、im s As StringPrivate Sub Form_Click()s=InputBox(”请输入年龄”)If s 30 ThenPrint”您的年龄为”;s,7,”请参加长跑运动”Elself s 40 ThenPrint”您的年龄为”;请参加跳绳运动”Elself s 100Print”1-2+3-4+5-6+99-100=;sEnd Sub4-12Private Sub Form_Click()Dim n As IntegerDim m As IntegerDim s As Integerm%=InputBox。请输入正整数”阶乘。n%=InputBox。请输入正整数 n(n=m

12、),“阶乘”)For m=m To nt=1For i=1 To mt=t*iNext is=s+tNext mPrint m!+(m+1)!+.+n!=;sEnd Sub4-13Private Sub Form_click()Dim a%Dim b%Dim c%For a=1 To 20For b=1 To 20For c=1 To 20lfa*a +b*b =c*c ThenPrint a,b,cEnd IfNext cNext bNext aEnd Sub4-14Private Sub Form_click()For n=1 To 500For i=1 To n-1If n Mod i=

13、0 Then s=s+Next iIf s=n Then Print i;s=0Next nPrintEnd Sub4-15Private Sub Form_click()Dim i As IntegerDim n As Longn=1t=1Do While t 0.00001e=e+1i=i+1n=n*it=1 /nLoopPrint e 的近似值是;eEnd Sub51Private SubForm_Click()Dim i%,x(1 To 5)As StringFor i=LBound(x)To UBound(x)x(i)=lnputBox(”x(&i&”)”)Next iFor i=U

14、Bound(x)To LBound(x)Step-1Print x(i)Next iPrintEnd Sub5-2Private Sub Form_Click()Dim i%5 ss=Array(1,2,3,4,5,6,7,8,9,10)For i=0 To 9If s(i)Mod 3=0 ThenPrint s(i);iElsePrintnuEnd IfNext iPrintEnd Sub5-3Option Base 1Private Sub Command1_Click()Dim x()x=Array(1,2,3,4,5,6,7,8,9,10)t=x(1)For i=1 To 9x(i)=

15、x(i+1)Print x(i);Nextx(10)=tPrint x(i)End SubPrivate Sub Command2_Click()Dim x()x=Array(1,2,3,4,5,6,7,8,9,10)t=x(10)For i=9 To 1 Step-1x(i+1)=x(i)Next ix(1)=tFor i=1 To 10Print x(i);Next iEnd Sub5-4Private Sub Form_Click()Dim a(5,5)For i=1 To 5Sum=0For j=1 To 5a(i,j)=lnt(Rnd*51+10)Sum=Sum+a(i,j)Prin

16、t a(i,j);Next jPrint SumNext iPrintFor i=1 To 5For j=1 To 5If i=j Then Print a(i,j);Next jNext iPrintEnd Sub5-5Private Sub Form_Click()Dim a()As IntegerDim Max As Integer,iMax As Integer,jMax AsIntegerDim Min As Integer,iMin As Integer,jMin As IntegerM=InputBox。输入 M)N=lnputBox(输入 N)ReDima(M,N)For i=

17、1 To MFor j=1 To Na(i,j)=lnt(Rnd*900)+100Next jNext iFor i=1 To MFor j=1 To NPrint a(i,j);Next jPrintNext iMax=a(1,1):Min=a(1,1)For i=1 To MFor j=1 To NIf a(i,j)Max Then Max=a(i,j):(Max=i:jMax=jf a(i,j)Min Then Min=a(i,j):iMin=i:jMin=jNext jNext iPrint,Max=n;Max,niMax=H;iMax,MjMax=;jMaxPrint Min;Min

18、,”iMin=;iMin,njMin=H;jMinErase aEnd Sub5-6Private Sub Form_Click()n=lnputBox(,nH)ReDim a(n,n)For i=1 To nForj=1 To nIf i=j Thena(i,j)=1Elsea(i,j)=0End IfNext jNext iFor i=1 To nForj=1 To nPrint a(i,j);Next jPrintNext iErase aEnd Sub5-7Private Sub Form_Click()Dim x As Variantx=Array(1,2,3,4,5,6,7,8,9

19、,10)For i=1 To 10Print x(i);Next iPrintFor i=1 To 7x(i)=x(i+3)Print x(i);Next iPrintReDim Preserve x(i)x=Array(1,2,3,4,5,6,7)or i=1 To 7Print x(i);Next iPrintEnd Sub5-8Option Base 1Private Sub Command1_Click(lndex As Integer)Select Case IndexCase 1Text3=Val(Textl)+Val(Text2)Case 2Text3=Textl-Text2Ca

20、se 3Text3=Textl*Text2Case 4Text3=Textl/Text2End SelectEnd Sub6-1Private Sub Form_click()Dim x As SingleDim y As SingleDim z As Singlex=lnputBox(请输入圆柱体的半径”)y=lnputBox(请输入圆柱体的高度”)volume x,y,zPrint”圆柱体的体积为”;zEnd Sub6-2窗体模块Private Sub Form_click()Dim a!,b!,c!a=lnputBox(请输入圆柱体的半径”)b=InputBox。请输入圆柱体的高度”)c

21、=volume(a,b)Print”圆柱体的体积为”;cEnd Sub标准模块Function volume(r As Single,h As Single)As Singlevolume=3.14*r*r*hEnd Function6-3Private Sub Form_Click()Dim y%y=lnputBox(请输入一个整数”)Call week(y)End Sub6-4窗体模块Private Sub Form_click()Dim a As Integer,b As Stringa=lnputBox(请输入一个整数”)b=week(a)Print b标准模块Function wee

22、k(s As Integer)As StringSelect Case sCase 0week=星期 HCase 1week=星期一Case 2week=星期二”Case 3week=星期三Case 4week=星期四”Case 5week=星期五Case 6week=星期六Case ElseMsg Box”数据无效”End SelectEnd Function6-5窗体模块Private Sub Form_click()Dim n As Single,w As Stringn=InputBox(请输入一个正整数”)Select Case wCase judge=0Print”此数为偶数”Ca

23、se ElsePrint”此数为奇数”Print wEnd SelectEnd Sub标准模块Function w(n As Single)As Stringw=n 2Select Case wCase w=0Print”此数为偶数”Case ElsePrint”此数为奇数”End Function6-7Sub lenUL(ByVal s As String,U%,L%)Dim i As IntegerFor i=1 To Len(s)Select Case Mid(s,i,1)Case”A”To ZU=U+1Case na To zL=L+1End SelectNext iEnd SubPr

24、ivate Sub Command1_Click()Dim U%,L%Call lenUL(Text1,U,L)Text2=UText3=LEnd SubPrivate Sub Command2_Click()Textl=Text2=Text3=Textl.SetFocusEnd Sub7-1Private Sub Command1_Click()Imagel.Picture=LoadPicture(c:图 片picture5.JPG)End SubPrivate Sub Command2_Click()Imagel.Picture=LoadPicture(c:图 片picture3.JPG)

25、End SubPrivate Sub Command3_Click()Imagel.Picture=LoadPicture(c:图 片picture4.JPG)End Sub7-2Private Sub Command1_Click()Static a As Integera=a+1If a Mod 2 0 ThenImagel.Picture=LoadPicture(c:图片p2.JPG)I mage2.Picture=LoadPicture(c:图片p1.JPG)ElseImagel.Picture=LoadPicture(c:图片p1.JPG)I mage2.Picture=LoadPi

26、cture(c:图片p2.JPG)End IfEnd SubPrivate Sub Form_Load()Imagel.Picture=LoadPicture(c:图片p1.JPG)I mage2.Picture=LoadPicture(c:图片p2.JPG)End Sub7-3Private Sub Timer1_Timer()Forml.Picture=I mage3.PictureImage3.Picture=Image2.PictureI mage2.Picture=Imagel PictureImagel.Picture=Forml.PictureEnd Sub7-4Private

27、Sub Form_Load()Timeri.Enabled=FalseEnd SubPrivate Sub Timer1_Timer()If lmage2.Top=-Image2.Height Thenlmage2.Top=lmage2.Top-100Elselmage2.Top=-Image2.HeightEnd IfEnd Sub7-5Private Sub Form_Load()HScroll1.Min=0HScrolH.Max=Imagel.WidthImagel.Width=0End SubPrivate Sub HScroll1_Scroll()Imagel.Width=HScro

28、lHLabel 1 =当前图片宽度:&HScrollLValueEnd Sub7-6Private Sub Command1_Click()For i=ProgressBarl.Min To ProgressBarl.MaxProgressBarl.Value=i(Forj=1 To 20000Next j)(延时)Next iEnd Sub7-7Private Sub Command1_Click()a=llf(Option1,“男”,女)b=llf(Option3,“硕士“,“博士”)c=llf(Check1,“音乐”d=llf(Check2,“演讲“,”)e=llf(Check3,“体育

29、f=llf(Check4,”集邮”)Text2=姓名:&Textl.Text&7&”性别:”&a&7&”学历:&b&7&”特长:&c&d&7&e&7&fEnd SubPrivate Sub Command2_Click()Textl=Text2=nTextl.SetFocusEnd Sub7-8Private Sub Form_Load()Combol.Additem 河南省Combol.Additem 开封市Combol.Additem 河南大学Combol.Additem 金明校区”Combol.Additem”环境与规划学院”Combol.Additem 09 级”Combol.Addi

30、tem”地理科学专业”Combol.Additem 刘彬Combol.Additem 毕业于Combol.Additem”湖南省”Combol.Additem 衡山县Combol.Additem 第二中学”Combol.Additem 218 班”End SubPrivate Sub Combol_Click()Listl.Additem Combol.TextEnd SubPrivate Sub List1_DblClick()Listl.Removeitem Listl.ListindexEnd Sub8-1Dim x As Single,y As SinglePrivate Sub Pt

31、1_Click()Pt1.Scale(0,100)-(100,0)Pt1.DrawWidth=2For x=0 To 100 Step 0.02Ptl.PSet(x,2),vbRedNext xFor y=0 To 100 Step 0.02Ptl.PSet(2,y),vbRedNext yPt1.CurrentX=2Ptl.CurrentY=5Pt1.Print(0,0)End Sub8-2Private Sub P1_Click()P1.Scale(0,100)-(100,0)P1.FillStyle=7P1.DrawWidth=5P1.FillColor=vbGreenPl.Line(1

32、0,90)-(90,10),vbRed,BEnd Sub8-3Private Sub Form_click()Scale(-100,100)-(100,-100)Line(-100,0)-(100,0)Line(0,-100)-(05 100)CurrentX=2CurrentY=6Print”(0,0)”End Sub8-4Private Sub Form_click()Scale(-100,100)-(100,-100)Line(-100,0)-(100,0)Une(0,-100)-(0,100)For x=-100 To 100 Step 0.02y=10*Sin(x)-10*Cos(2

33、*x)PSet(x,y),vbRedNext xEnd Sub8-7Private Sub Form_Click()Timeri.Enabled=TrueEnd SubPrivate Sub Timeri_Timer()RandomizeScale(-120,120)-(120,-120)DrawWidth=2If r 100 Thenr=r+2For r=0 To 100Circle(0,0),r,RGB(255*Rnd,255*Rnd,255*Rnd)Next rEnd IfEnd Sub9-1Private Sub Text1_KeyPress(K As Integer)K=K+3End

34、 Sub9-2Private Sub Text1_KeyPress(K As Integer)Select Case KCase 48 To 57K=KCase ElseK=0End SelectEnd Sub9-6Private Sub Command1_MouseMove(Button AsInteger,Shift As Integer,X As Single,Y As Single)MousePointer=5End SubPrivate Sub Text1 _MouseMove(Button As Integer,Shift As Integer,X As Single,Y As S

35、ingle)MousePointer=11End SubPrivate Sub Picture1_Click()Mouseicon=Picturel.MouseiconPicturel.Mouseicon=I magel.MouseiconImagel.Mouseicon=Forml.MouseiconEnd Sub9-7Sub Form_MouseMove(Button As Integer,Shift AsInteger,X As Single,Y As Single)If Shift=vbCtrlMask And Button=vbLeftButtonThen Print”Ctrl+左键

36、+移动”If Shift=vbAltMask And Button=vbRightButtonThen Print Alt+右键+移动”End SubSub Form_MouseUp(Button As Integer,Shift AsInteger,X As Single,Y As Single)CisEnd Sub9-8Sub Picture1_MouseMove(Button As Integer,ShiftAs Integer,X As Single,Y As Single)If Button=vbLeftButton Then Picturel.Print Str(X)+Str(Y)

37、BackColor=RGB(Rnd*256,Rnd*256,Rnd*256)End Sub10-1Private Sub Command1_Click()Open d:data1.txt For Output As#1Write#1,”601 杨大昌;“4550”Write#1,“603”,“李文圣“;“3886”Write#1,“605“,“张燕“;“2235”Close#1End SubPrivate Sub Command2_Click()Open d:data1.txt*For Input As#2Do While Not EOF(2)Input#2,X1,X2,x3Print X1,

38、X2,x3LoopCloseEnd Sub10-2Private Sub Command1_Click()Open d:data1.txt For Append As#3Write#3,Textl,Text2,Text3Textl=H,Text2=Text3=CloseEnd SubPrivate Sub Command2_Click()CloseEndEnd Sub10-5Private Sub Form_Click()Dim sum As LongFor n=1 To 100 Step 2sum=sum+nNext nPrint sumEnd SubPrivate Sub Form_Loa

39、d()Open d:data5.txt For Output As#1For n=1 To 100 Step 1Print#1,n;Next nCloseEnd Sub10-6Private Sub Form_Click()Dim sum As IntegerFor n=10 To 100 Step 10sum=sum+nNextPrint sumEnd SubPrivate Sub Form_Load()Open d:data6.dat For Random As#1For n=1 To 100Put#1,nNextEnd Sub11-1Private Sub Command1_Click(

40、)CommonDialogl.Action=3Textl.BackColor=CommonDialogl.ColorEnd SubPrivate Sub Command2_Click()CommonDialogl.Flags=263CommonDialogl.Action=4Textl.FontSize=CommonDialogl.FontSizeTextl.FontName=CommonDialogl.FontNameTextl.FontBold=CommonDialogl.FontBoldTextl.FontStrikethruCommonDialogl.FontStrikethruTex

41、tl.ForeColor=CommonDialogl.ColorTextl.FontUnderline=CommonDialogl.FontUnderlineEnd SubPrivate Sub Command3_Click()CommonDialogl.Action=2End Sub11-2Private Sub Command1_Click()CD1.InitDir=C:Documents andSettingsAdministrator桌面”CD1.Filter=图片jpg|文本文件CD1.ShowOpenIf CD1.Filterindex=1 ThenImagel.Picture=L

42、oadPicture(CD1.FileName)ElseOpen CD1.FileName For Input As#1Do While Not EOF(1)Line Input#1,nTextl=Textl+n+vbNewLineLoopEnd IfEnd Sub11-4Private Sub Form_Resize()Textl.Left=50Textl.Top=50Textl.Width=Width-2000Textl.Height=Height-5000End SubPrivate Sub mnuName_Click(lndex As Integer)Select Case Index

43、Case 5Textl.FontName=宋体”Case 10Textl.FontName=黑体Case 15Textl.FontName=”隶书”End SelectEnd Sub11-6Private Sub Form_Load()Textl.Width=WidthTextl.Height=HeightEnd SubPrivate Sub Form_Resize()Textl.Left=50Textl.Top=650Textl.Width=Width-200Textl.Height=Height-900End SubPrivate Sub mnuCopy_Click()s=Textl.Se

44、lTextmnuPaste.Enabled=TrueEnd SubPrivate Sub mnuCut_Click()s=Textl.SelTextTextl.SelText=mnuPaste.Enabled=TrueEnd SubPrivate Sub mnuPaste_Click()Textl.SelText=Textl+sEnd Sub11-7Private Sub Form_MouseDown(Button As Integer,Shift As Integer,X As Single,Y As Single)PopupMenu mnuTitle,2,0,0End SubPrivate Sub mnuDate_Click()Caption=DateBackColor=vbYellowEnd SubPrivate Sub mnuTime_Click()Caption=TimeBackColor=vbRedEnd Sub

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁