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
习题答案:
一. 选择题:
1.A 2.B 3.C 4.D 5.C 6.C 7.A 8.B 9.C 10.C 11.D 12.C 13.D 14.D 15.C 16.A
二. 填空题
1.目录列表框 2.文本 3.Close #1 4.GFEDCBA 5. EOF(Fileno) #Fileno,L 6.len(LastRecord) filelen(“score”) 7.close #1 FreeFile chr
8. “data.txt” for input as #11 not EOF(11) s Insert(a(i),0) Preserve b(UBound(b)+1) a(i)
9. LineInput(#1,st) print #3, ,subSt Mid(st,i+1,1) p 三. 改错题
第一题:
Private Sub Command1_Click() Dim s As String, i As Integer s = Text1.Text Call sub1(s)
Open \For i = Len(s) To 1 Step -1 Print #12, Mid(s, i, 1) Next
Close #12 End Sub
Private Sub sub1(st As String)
Dim i As Integer, l As Integer, k As Integer Dim p As Integer, al As String * 1 For i = 1 To Len(st) al = Mid(st, i, 1) p = i + 1
Do Until p > Len(st)
If al = Mid(st, p, 1) Then
For k = p To i + 1 Step -1
Mid(st, k, 1) = Mid(st, k - 1, 1) Next
Mid(st, i + 1, 1) = al Exit Do Else
p = p + 1 End If Loop Next End Sub
第二题:
Option Explicit
Private Function SuShu(m As Long) As Boolean Dim i As Long
For i = 2 To Int(Sqr(m))
If m Mod i = 0 Then Exit Function Next
SuShu = True End Function
Private Sub Form_Click() Dim st As String, c As String Dim num As Long, a() As Long
Dim i As Long, j As Long, k As Long
st = InputBox(\请输入任一数字串\查找素数\c = \i = 1 k = 1
Do While i <= Len(st) If k <= Len(st) Then c = c + Mid(st, k, 1) num = Val(c)
If SuShu(num) Then j = j + 1
ReDim Preserve a(j) a(j) = num End If k = k + 1 Else
c = \ i = i + 1 k = i End If Loop
Open \
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库第一章 VB开发环境与VB概述 习题答案(8)在线全文阅读。
相关推荐: