VB程序设计第三版实验H
答案
八年级地理上册填图题岩土工程勘察试题省略号的作用及举例应急救援安全知识车间5s试题及答案
VB程序设计第三版实验H答案(全)
1
Private Sub Command1_Click() Open "c:\score" For Output As #1 Print #1, "051023", "王海涛", 66
Print #1, "052498", "周文英", 88
Print #1, "050992", "陈建东", 77
Open "c:\score1" For Output As #2 Write #2, "051023", "王海涛", 66
Write #2, "052498", "周文英", 88
Write #2, "050992", "陈建东", 77
Close
i1 = Shell("NOTEPAD.exe" + " c:\score", vbNormalNoFocus)
i2 = Shell("NOTEPAD.exe" + " c:\score1", vbNormalNoFocus)
End Sub
Private Sub Command2_Click() Dim no As String, name As String, s As Integer
Open "c:\score" For Input As #1 Do While Not EOF(1)
Line Input #1, linedata
List1.AddItem linedata
Loop
Open "c:\score1" For Input As #2 Do While Not EOF(2)
Input #2, no, name, s
List2.AddItem no & name & s Loop
Close
End Sub
2
Private Sub Command1_Click() Dim fib%(0 To 9), i%
Open "c:\fb.dat" For Output As #1 For i = 0 To 9
If i = 0 Or i = 1 Then
fib(i) = i
Else
fib(i) = fib(i - 1) + fib(i - 2)
End If
Print #1, """Fib(" & i & ")""," & fib(i)
Next i
Close #1
i = Shell("NOTEPAD.exe" + " c:\fb.dat", vbNormalNoFocus)
End Sub
Private Sub Command2_Click() Dim st$, n%, sum%
Open "c:\fb.dat" For Input As #1 Do While Not EOF(1)
Input #1, st, n
sum = sum + n
List1.AddItem st & "=" & n Loop
Close #1
List1.AddItem "合计:" & sum
List1.AddItem "平均:" & sum / 10 End Sub
3
4
Private Type studtype
no As String * 4
name As String * 6
mark As Single
End Type
Dim student As studtype, stud(1 To 5) As studtype, t As studtype
Private Sub Command1_Click() Open "d:\score.dat" For Random As #1 Len = Len(student)
With student
.no = "0001"
.name = "星期一"
.mark = 66
End With
Put #1, 1, student
With student
.no = "0002"
.name = "星期二"
.mark = 99
End With
Put #1, 2, student
With student
.no = "0003"
.name = "星期三"
.mark = 88
End With
Put #1, 3, student
With student
.no = "0004"
.name = "星期四"
.mark = 55
End With
Put #1, 4, student
With student
.no = "0005"
.name = "星期五"
.mark = 77
End With
Put #1, 5, student
Close #1
End Sub
Private Sub Command2_Click() Open "d:\score.dat" For Random As #1 Len = Len(student)
For i = 1 To 5
Get #1, i, student
Print student.no, student.name, student.mark
stud(i) = student
Next i
Close #1
For i = 1 To 5
For j = i + 1 To 5
If stud(i).mark > stud(j).mark Then t = stud(i): stud(i) = stud(j): stud(j) = t
Next
Next i
Open "d:\random1.dat" For Random As #2 Len = Len(student)
For i = 1 To 5
Put #2, i, stud(i)
Next i
Close #1
End Sub
Private Sub Command3_Click() Open "d:\random1.dat" For Random As #1 Len = Len(student)
For i = 1 To 5
Get #1, i, stud(i)
Print stud(i).no; stud(i).name; stud(i).mark
Next i
Close #1
End Sub
5
Private Type studtype
no As Integer
name As String * 20
sex As String * 1
mark As Single
End Type
Dim std As studtype
Dim record As Integer
Private Sub Command1_Click() With std
.no = Val(Text1.Text)
.name = Text2.Text
.sex = IIf(Option1.Value, "1", "0")
.mark = Val(Text3.Text) End With
Open "c:\score" For Random As #1 Len = Len(std)
record = LOF(1) / Len(std) + 1 Label1.Caption = record Put #1, record, std
Close #1
End Sub
Private Sub Command2_Click() Open "c:\score" For Random As #1 Len = Len(std)
record = Val(Text4.Text) Get #1, record, std
Text1.Text = std.no
Text2.Text = std.name
If std.sex = "1" Then
Option1.Value = True
Else
Option2.Value = True
End If
Text3.Text = std.mark
record = LOF(1) / Len(std) Close #1
End Sub
Private Sub Command3_Click() With std
.no = Val(Text1.Text)
.name = Text2.Text
.sex = IIf(Option1.Value, "1", "0")
.mark = Val(Text3.Text) End With
Open "c:\score" For Random As #1 Len = Len(std)
record = Val(Text4.Text) Put #1, record, std
Close #1
End Sub
Private Sub Command4_Click() Open "c:\score" For Random As #1 Len = Len(std)
record = 1
Get #1, record, std
Text1.Text = std.no
Text2.Text = std.name
If std.sex = "1" Then
Option1.Value = True
Else
Option2.Value = True
End If
Text3.Text = std.mark
record = LOF(1) / Len(std) Close #1
Text4.Text = 1
End Sub
Private Sub Command5_Click() Open "c:\score" For Random As #1 Len = Len(std)
record = Val(Text4.Text) - 1 If Val(Text4.Text) <= 1 Then MsgBox "超出记录范围", 2 + vbExclamation, "警告": Close #1 Else
Get #1, record, std
Text1.Text = std.no
Text2.Text = std.name
If std.sex = "1" Then
Option1.Value = True
Else
Option2.Value = True
End If
Text3.Text = std.mark
record = LOF(1) / Len(std) Close #1
Text4.Text = Val(Text4.Text) - 1 End If
End Sub
Private Sub Command6_Click() Open "c:\score" For Random As #1 Len = Len(std)
record = Val(Text4.Text) + 1 If record > Val(Label1.Caption) Then
MsgBox "超出记录范围", 2 + vbExclamation, "警告": Close Else
Get #1, record, std
Text1.Text = std.no
Text2.Text = std.name
If std.sex = "1" Then
Option1.Value = True
Else
Option2.Value = True
End If
Text3.Text = std.mark
record = LOF(1) / Len(std) Close #1
Text4.Text = Val(Text4.Text) + 1 End If
End Sub
Private Sub Command7_Click() Open "c:\score" For Random As #1 Len = Len(std)
record = Val(Label1.Caption) Get #1, record, std
Text1.Text = std.no
Text2.Text = std.name
If std.sex = "1" Then
Option1.Value = True
Else
Option2.Value = True
End If
Text3.Text = std.mark
record = LOF(1) / Len(std) Close #1
Text4.Text = record
End Sub
Private Sub Form_Load() Open "c:\score" For Random As #1 Len = Len(std)
Label1.Caption = LOF(1) / Len(std)
Close #1
End Sub
6
Private Type studtype
no As Integer
name As String * 6
mark As Integer
End Type
Dim std As studtype
Dim record As Integer
Private Sub Command1_Click() With std
.no = Val(Text1.Text)
.name = Text2.Text
.mark = Val(Text3.Text) End With
Open "c:\score1" For Random As #1 Len = Len(std)
record = LOF(1) / Len(std) + 1 Put #1, record, std
Close #1
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End Sub
Private Sub Command2_Click() Dim sum, count As Integer Open "c:\score1" For Random As #1 Len = Len(std)
For i = 1 To record
Get #1, i, std
sum = sum + std.mark
count = count + 1
List1.AddItem std.no & " " & std.name & std.mark
Next i
List1.AddItem "总分" & sum
List1.AddItem "平均成绩" & sum / count Close #1
End Sub
7
Private Sub Command1_Click() Dim inputdata1, inputdata2, inputdata3 As String * 1
Dim v, byt1() As Byte, byt2() As Byte, flen1 As Long, flen2 As Long, fnum, fnum3 As Integer
Text1.Text = "": Text2.Text = "": Text3.Text = ""
CommonDialog1.ShowOpen
fname1 = CommonDialog1.FileName CommonDialog2.ShowOpen
fname2 = CommonDialog2.FileName Open fname1 For Binary As #1
Open fname2 For Binary As #2
Do While Not EOF(1)
inputdata1 = Input(1, #1)
Text1.Text = Text1.Text + inputdata1 Loop
Do While Not EOF(2)
inputdata2 = Input(1, #2)
Text2.Text = Text2.Text + inputdata2 Loop
fnum3 = FreeFile
Open "c:\hb.txt" For Binary As #fnum3 Put #fnum3, 1, byt1()
Put #fnum3, flen1 + 1, byt2() Do While Not EOF(fnum3)
inputdata3 = Input(1, #fnum3) Text3.Text = Text3.Text + inputdata3 Loop
If Dir(fname1) <> "" Then
fnum = FreeFile
Open fname1 For Binary As #fnum
flen1 = LOF(fnum)
ReDim byt1(flen1 - 1)
Get #fnum, 1, byt1()
Close fnum
End If
If Dir(fname2) <> "" Then
fnum = FreeFile
Open fname2 For Binary As #fnum
flen2 = LOF(fnum)
ReDim byt2(flen2 - 1)
Get #fnum, 1, byt2()
Close fnum
End If