《VB程序设计教程》答案汇总.doc_第1页
《VB程序设计教程》答案汇总.doc_第2页
《VB程序设计教程》答案汇总.doc_第3页
《VB程序设计教程》答案汇总.doc_第4页
《VB程序设计教程》答案汇总.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

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

文档简介

随机数产生Private Sub Form_Click() For i = 101 To 200 Step 2 For j = 2 To i - 1 If i Mod j = 0 Then Exit For Next j If j = i Then List1.AddItem i Next iEnd Sub四 实验21Private Sub Command1_Click() For i = 100 To 200 For j = 10 To 14 If i = j 2 Then n = n + 1 m = i End If Next j Next i Text1 = m Text2 = n End Sub4 实验16Private Sub Form_Click() s = 1 While s = 100000 i = i + 1 s = s * (2 * i) Wend Print s=; sEnd Sub4 实验 17Private Sub Form_Click() Do While Sum = 5000 i = i + 1 Sum = Sum + i i Loop Print sum=; Sum - i iEnd Sub4 实验 23Private Sub Form_Click() Dim a As Intege r, b As Integer a = Int(100 * Rnd + 1) b = Int(100 * Rnd + 1) Text1 = a Text2 = b r = a Mod b While r 0 a = b b = r r = a Mod b Wend Text3 = b c = (Val(Text1) * Val(Text2) / b Text4 = cEnd Sub6 实验8Private Sub Form_Click() Randomize Dim a(8, 8) As Integer For i = 1 To 8 For j = 1 To 8 a(i, j) = Int(999 - 100 + 1) * Rnd + 100) Print a(i, j); If Max = a - 1 Then Text2.Text = 是素数 Else Text2.Text = 不是素数 End If5.6Private Sub Option1_Click() Shape1.Shape = 3End SubPrivate Sub Option2_Click() Shape1.Shape = 1End Sub Private Sub Option3_Click() Shape1.Shape = 4End SubPrivate Sub Option4_Click() Shape1.Shape = 2End Sub5.9Private Sub Command1_Click() For i = o To List1.ListCount - 1 If List1.List(i) = Text1.Text Then Exit For Next i If i = List1.ListCount Then List1.AddItem Text1.Text End If Text1.SetFocus Text1.SelStart = 0 Text1.SelLength = Len(Text1)End SubPrivate Sub Command2_Click() If List1.ListIndex = -1 Then MsgBox 请选择要删除的项 Else List1.RemoveItem List1.ListIndex End IfEnd SubPrivate Sub Command3_Click() List1.ClearEnd Sub5.10Private Sub Combo1_Click() Select Case Combo1.ListIndex Case 0 Text1.ForeColor = vbWhite Case 1 Text1.ForeColor = vbBlack Case 2 Text1.ForeColor = vbRed Case 3 Text1.ForeColor = vbGreen Case 4 Text1.ForeColor = vbBlue Case 5 Text1.ForeColor = vbYellow End SelectEnd SubPrivate Sub Combo2_Click()Select Case Combo2.ListIndex Case 0 Text1.BackColor = vbWhite Case 1 Text1.BackColor = vbBlack Case 2 Text1.BackColor = vbRed Case 3 Text1.BackColor = vbGreen Case 4 Text1.BackColor = vbBlue Case 5 Text1.BackColor = vbYellow End SelectEnd SubPrivate Sub Combo3_Click() Select Case Combo3.ListIndex Case 0 Text1.Alignment = 0 Case 1 Text1.Alignment = 2 Case 2 Text1.Alignment = 1 End SelectEd Sub5.13Private Sub Command1_Click() Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click() Timer1.Enabled = flaseEnd SubPrivate Sub Timer1_Timer() Label2.Caption = TimeEnd SubPrivate Sub Timer2_Timer() If Text1 = Hour(Time) Then If Text2 = Minute(Time) Then Beep End If End IfEnd Sub5.14Private Sub Timer1_Timer()Static i As Integer Select Case i Mod 2 Case 0 Text1.BackColor = vbRed Case 1 Text1.BackColor = vbGreen End Select i = i + 1End Sub5.15Private Sub Command1_Click() Timer1.Enabled = FalseEnd SubPrivate Sub Command2_Click() Timer1.Enabled = TrueEnd SubPrivate Sub Timer1_Timer() If Label1.Left 100 Then MsgBox 输入有误,请重新输入 End If List1.AddItem score(i) Sum = Sum + score(i) Next i For Each x In score If Max x Then Min = x Next x For j = 1 To 9 For k = j + 1 To 10 If score(j) score(k) Then t = score(j) score(j) = score(k) score(k) = t End If Next k Next j For Each y In score List2.AddItem y Next y Text1 = Sum / 10 Text2 = Max Text3 = MinEnd Sub练习2Private Sub Command1_Click() Dim a(1 To 10) As Integer, b(1 To 10) As Integer For i = 1 To 10 a(i) = Int(91 * Rnd + 10) Next i For i = 1 To 10 List1.AddItem a(i) Next i For i = 10 To 1 Step -1 List2.AddItem a(i) Next iEnd Sub排序 Dim a(1 To 10) As IntegerPrivate Sub Command1_Click()RandomizeFor i = 1 To 10 a(i) = Int(99 - 10 + 1) * Rnd + 10) Text1 = Text1 & a(i) & Next iEnd SubPrivate Sub Command2_Click()Rem 比较法排序For i = 1 To 9 For j = i + 1 To 10 If a(i) a(j) Then t = a(i) a(i) = a(j) a(j) = t End If Next jNext iFor i = 1 To 10 Text2 = Text2 & a(i) & Next iEnd SubPrivate Sub Command3_Click()Rem 冒泡法排序For i = 1 To 9 For j = 1 To 10 - i If a(j) a(j + 1) Then t = a(j) a(j) = a(j + 1) a(j + 1) = t End If Next jNext iFor i = 1 To 10 Text3 = Text3 & a(i) & Next iEnd SubPrivate Sub Command4_Click()For i = 1 To 9 k = i For j = i + 1 To 10 If a(k) a(j) Then k = j Next j If a(k) a(i) Then t = a(k) a(k) = a(i) a(i) = t End If Next iFor i = 1 To 10 Text4 = Text4 & a(i) & Next iEnd SubPrivate Sub Form_Load()Text1 = Text2 = Text3 = 升序排序Dim a() As Integer Dim n As IntegerPrivate Sub Command1_Click() Randomize n = Val(InputBox(number) ReDim a(n) For i = 1 To n a(i) = Int(90 * Rnd + 10) List1.AddItem a(i) Next iEnd SubPrivate Sub Command2_Click()(比较法) For i = 1 To n - 1 For j = i + 1 To n If a(i) a(j) Then t = a(i) a(i) = a(j) a(j) = t End If Next j Next i For i = 1 To n List2.AddItem a(i) Next iEnd SubPrivate Sub Command2_Click()(冒泡法) For i = 1 To n - 1 For j = 1 To n - i If a(j) a(j + 1) Then t = a(j) a(j) = a(j + 1) a(j + 1) = t End If Next j Next i For i = 1 To n List2.AddItem a(i) Next iEnd Sub习题6.3Private Sub Command1_Click() Randomize For i = 1 To 4 For j = 1 To 4 a(i, j) = Int(999 - 100 + 1) * Rnd + 100) Picture1.Print a(i, j); If i = j Or i + j = 5 Then s = s + a(i, j) Next j Picture1.Print Next i Text1 = sEnd SubPrivate Sub Command2_Click() Rem For j = 1 To 4 t = a(1, j) a(1, j) = a(3, j) a(3, j) = t Next j For i = 1 To 4 For j = 1 To 4 Picture2.Print a(i, j); Next j Picture2.Print Next iEnd SubPrivate Sub Command3_Click() For i = 1 To 4 Picture2.Print Tab(5 * i); For j = i To 4 Picture2.Print a(i, j); Next j Picture2.Print Next iEnd SubPrivate Sub Command4_Click() For i = 1 To 4 For j = 1 To i Picture2.Print a(i, j); Next j Picture2.Print Next iEnd Sub习题7.1Function sum(n) As Integer For i = 1 To n s = s + i Next i sum = sEnd FunctionPrivate Sub Command1_Click() i = Text1 j = Text

温馨提示

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

评论

0/150

提交评论