vb习题参考答案(5.2-5.4).doc_第1页
vb习题参考答案(5.2-5.4).doc_第2页
vb习题参考答案(5.2-5.4).doc_第3页
vb习题参考答案(5.2-5.4).doc_第4页
vb习题参考答案(5.2-5.4).doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

52答案一、选择题1-10:ADBAD BABBB11-:BDDBA(15题BackColor去掉空格,FillSte全部漏了y)二、判断题TTFFF FFFTF三、1、1000Timer1.Enabled = true0h=(x Mod 3600) 60s = (x Mod 3600) Mod 602、n=3 x=42 y=9四、程序设计题1、Private Sub Command1_Click()For i = 0 To List1.ListCount - 1 List3.AddItem List1.List(i)Next iFor i = 0 To List2.ListCount - 1 List3.AddItem List2.List(i)Next iEnd Sub2、Private Sub Form_Load()Label1.Left = 0Label1.Top = 0End SubPrivate Sub Timer1_Timer()Static iIf i = 0 Then Label1.BackColor = vbRedElseIf i = 1 Then Label1.BackColor = vbBlueElse Label1.BackColor = vbGreen i = -1End Ifi = i + 1If Label1.Top Form1.Height ThenLabel1.Left = 0Label1.Top = 0ElseLabel1.Left = Label1.Left + (Form1.ScaleWidth - Label1.Width) / 10Label1.Top = Label1.Top + (Form1.ScaleHeight - Label1.Height) / 10End IfEnd Sub补充1. 建立如图所示窗体,编写一个模拟秒表的程序。程序运行时,“启动”按钮可用,“停止”按钮不可用。当单击“启动”按钮时,在标签1中显示当时的时间,“启动”按钮不可用,而“停止”可用。过一会,单击“停止”按钮时,在标签2中显示结束时间,在标签3中显示所用的时间,此时“启动”可用,“停止”又变为不可用。Dim t1 As DoubleDim t2 As DoublePrivate Sub Command1_Click()t1 = NowLabel1.Caption = Format(t1, hh:mm:ss)Label2.Caption = Format(t1, hh:mm:ss)Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click()Timer1.Enabled = FalseLabel3.Caption = Format(t2 - t1, hh:mm:ss)End SubPrivate Sub Form_Load()Timer1.Interval = 1000Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()t2 = NowLabel2.Caption = Format(t2, hh:mm:ss)End Sub53答案一、选择题 DBDDC BCDA二、 TTTTT三、1、2 5 9 2、a()b(k) = b(11 - k)b(11 - k) = t3、n=1 z=4 n=2 z=7 n=3 z=10四、程序设计题1、子过程和函数过程各一个做法Sub subsushu(x As Integer, k As Boolean)k = TrueFor i = 2 To x - 1 If x Mod i = 0 Then k = False Exit For End IfNext iEnd Sub或者Function fsushu(x As Integer) As Booleanfsushu = TrueFor i = 2 To x - 1 If x Mod i = 0 Then fsushu = False Exit For End IfNext iEnd FunctionPrivate Sub Command1_Click()Dim k As Booleanx% = InputBox(input x:)Call subsushu(x, k)If k = True Then Print x; 是素数Else Print x; 非素数End IfEnd SubPrivate Sub Command2_Click()x% = InputBox(input x:)If fsushu(x) = True Then Print x; 是素数Else Print x; 非素数End IfEnd Sub2、Option Base 1Sub fmax(a() As Integer, max)max = a(1)For i = 1 To UBound(a) If a(i) max Then max = a(i) End IfNext iEnd SubPrivate Sub Command1_Click()Dim a(10) As IntegerFor i = 1 To 10 a(i) = Rnd * 100Next iFor i = 1 To 10 Print a(i);Next iPrintCall fmax(a(), max)Print max=; maxEnd Sub3、Function xsum(x)Sum = 1For i = 1 To x Sum = Sum + x iNext ixsum = SumEnd FunctionPrivate Sub Command1_Click()a = 3b = 5c = 7d = 9Print a / xsum(a) + b / xsum(b) + c / xsum(c) + d / xsum(d)End Sub4、Function sp(ss, sc, sr)Do While InStr(ss, sc) 0 x = InStr(ss, sc) If x = 1 Then ss = sr & Right(ss, Len(ss) - Len(sc) Else s1 = Left(ss, x - 1) s2 = Right(ss, Len(ss) - (x - 1) - Len(sc) ss = s1 & sr & s2 End IfLoopsp = ssEnd FunctionPrivate Sub Command1_Click()ss = abcabcbcsc = bcsr = 99Print sp(ss, sc, sr)End Sub54答案一、选择题BCBAA BBBA二、1、“文本文件(*.txt)|*.txt”CommonDialog1.FileName2、Form1.Hide三、1、2题合并如下Private Sub baocun_Click()CommonDialog1.ShowSaveOpen CommonDialog1.FileName For Output As #1Print #1, Text1.TextClose #1End SubPrivate Sub beijingse_Click()CommonDialog1.ShowColorText1.BackColor = CommonDialog1.ColorText1.BackColor = CommonDialog1.ColorEnd SubPrivate Sub dakai_Click()CommonDialog1.ShowOpenOpen CommonDialog1.FileName For Input As #1 While Not EOF(1) Line Input #1, i Text1.Text = Text1.Text & i & vbCrLf WendClose #1End SubPrivate Sub qianjingse_Click()CommonDialog1.ShowColorText1.ForeColor = CommonDialog1.

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论