vb程序设计实验教程与习题选解 王杰华 郑国平 主编(8)

2019-04-10 10:17

习题答案 选择题

1.D 2.A 3.B 4.D 5.B 6.B 7.C 8.C 9.C

填空题

1.中断 2.ctrl+break 3.本地 4.debug.print k

改错题

Option Explicit Option Base 1

Private Sub Form_Click()

Dim a(10) As Integer, i As Integer, j As Integer Dim b(10) As Integer, k As Integer, l As Integer Randomize For i = 1 To 10

a(i) = Int(Rnd * 19) + 1 Print a(i); Next Print j = 1 k = 10

For i = 1 To 10

For l = 2 To a(i) - 1

If a(i) Mod l = 0 Then Exit For Next

If l = a(i) Then b(j) = a(i) j = j + 1 Else

b(k) = a(i) k = k - 1 End If Next

For i = 1 To 10 Print b(i); Next Print

End Sub

编程题

Option Explicit Option Base 1

Private Sub Command1_Click() Dim i As Integer

For i = 1 To Len(Text1.Text)

Text2.Text = Text2.Text & Convert(Mid(Text1.Text, i, 1)) & vbCrLf Next End Sub

Private Function Convert(a As String) As String Dim Ascii As Integer Dim Binary As String Ascii = Asc(a) Do While Ascii > 0

Binary = Ascii Mod 2 & Binary Ascii = Ascii \\ 2 Loop

Convert = Binary End Function

第八章文件实验答案

实验

8_1图片浏览器:

Private Sub Dir1_Change() File1.Path = Dir1.Path End Sub

Private Sub Drive1_Change() Dir1.Path = Drive1.Drive End Sub

Private Sub File1_DblClick() Dim fileName As String

fileName = File1.Path + \Image1.Picture = LoadPicture(fileName)

HScroll1.Max = Image1.Width - Picture1.Width + VScroll1.Width VScroll1.Max = Image1.Height - Picture1.Height + HScroll1.Height If Image1.Width > Picture1.Width Then

HScroll1.LargeChange = HScroll1.Max / 10 HScroll1.SmallChange = VScroll1.Max / 20 HScroll1.Enabled = True Else

HScroll1.Enabled = False End If

If Image1.Height > Picture1.Height Then

VScroll1.LargeChange = VScroll1.Max / 10 VScroll1.SmallChange = VScroll1.Max / 20 VScroll1.Enabled = True Else

VScroll1.Enabled = False End If End Sub

Private Sub Form_Load() File1.Pattern = \Image1.Left = 0: Image1.Top = 0

HScroll1.Top = Picture1.Height - HScroll1.Height - 50 HScroll1.Left = 0

HScroll1.Width = Picture1.Width - 50 VScroll1.Top = 0

VScroll1.Left = Picture1.Width - VScroll1.Width - 50 VScroll1.Height = Picture1.Height - HScroll1.Height - 50 HScroll1.Min = 0: VScroll1.Min = 0 End Sub

Private Sub HScroll1_Change() Image1.Left = -HScroll1.Value End Sub

Private Sub VScroll1_Change() Image1.Top = -VScroll1.Value End Sub

实验8_2 顺序文件操作

Option Base 1

Dim a(4, 4) As Integer

Private Sub Command1_Click() Dim s As Integer Dim i As Integer Dim j As Integer

Open \ Do While Not EOF(12) i = j \\ 4 + 1

Input #12, a(i, (j Mod 4) + 1) j = j + 1 Loop

For i = 1 To 4 For j = 1 To 4

Picture1.Print Format(a(i, j), \ Next

Picture1.Print Next

Close #12

Command2.Enabled = True End Sub

Private Sub Command2_Click() Dim i As Integer Dim j As Integer Dim sum As Integer For i = 1 To 4

sum = sum + a(i, i) Next

Text1.Text = sum End Sub

Private Sub Command3_Click() End End Sub

实验8_3 记录文件操作 Option Explicit Option Base 1

Private Type Stu_Score

Studentname As String * 6 Language As Integer Math As Integer

English As Integer End Type

Dim Student As Stu_Score Dim Filenum As Integer Dim Reclength As Long Dim str As String

Private Sub Command1_Click() Student.Studentname = Text1 Student.Language = Text2 Student.Math = Text3 Student.English = Text4 Print List1.ListIndex

List1.AddItem Text1 & \ \ \End Sub

Private Sub Command2_Click()

Text1 = \End Sub

Private Sub Form_Load() Filenum = FreeFile

Reclength = Len(Student)

Open \List1.AddItem \姓名 语文 数学 英语\Do While Not EOF(Filenum) Get #Filenum, , Student With Student

str = .Studentname & \ \ str = str & .Math & \ \ List1.AddItem str End With Loop

List1.RemoveItem (List1.ListCount - 1)

End Sub

Private Sub Form_Unload(Cancel As Integer) Close #Filenum End Sub

\


vb程序设计实验教程与习题选解 王杰华 郑国平 主编(8).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2013年年度管理方案书

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: