VB6.0随机文件问题
以下使问题。需要处理的教师数据类型已在标准模块Module1中定义,请按以下给定菜单功能设计程序①Form1窗体的“保存输入数据”菜单的功能是将当前输入的某个教师数据保存...
以下使问题。需要处理的教师数据类型已在标准模块Module1中定义,请按以下给定菜单功能设计程序①Form1窗体的“保存输入数据”菜单的功能是将当前输入的某个教师数据保存到名为:App.path & “\teacher.dat”随机文件中,保存后用MsgBox输出“数据已保存!”信息,并清空Text1—Text4;②Form1窗体的“查询教师教龄”菜单的功能是从当前窗体切换到Form2窗体;③ Form1窗体的“退出”菜单即结束程序;④Form2窗体的“查询”菜单功能是将存储教师数据的文件:App.path & “\teacher.dat”打开,读出所有记录数据计算所有教师的最长教龄、最短教龄与平均教龄,然后在Picture1控件中第2行第6列打印;⑤Form2窗体的“返回”菜单功能是从当前Form2窗体切换回Form1窗体。
展开
1个回答
展开全部
标准模块Module1代码:
Public Type Teacher
Identifier As String * 10
Name As String * 8
Title As String * 6
TeachingAge As Integer
Wages As Single
End Type
窗体Form1代码:
Private Sub QueryTeachingAge_Click()
Load Form2
Form2.Show
Unload Form1
End Sub
Private Sub Quit_Click()
End
End Sub
Private Sub SaveInputData_Click()
Dim Teac As Teacher
Dim RecordNumber As Single
With Teac
.Identifier = Text1.Text
.Name = Text2.Text
.TeachingAge = Text3.Text
.Wages = Text4.Text
For i = Option1.LBound To Option1.UBound
If Option1(i).Value Then .Title = Option1(i).Caption
Next i
End With
Open "D:\Teacher.dat" For Random As #1 Len = Len(Teac)
RecordNumber = LOF(1) / Len(Teac) + 1
Put #1, RecordNumber, Teac
Close #1
MsgBox "数据已保存!"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
窗体Form2代码:
Private Sub Query_Click()
Picture1.Cls
Dim Teac As Teacher
Dim RecordNumber As Long
Dim TeachingAgeMax As Integer, TeachingAgeMin As Integer, TeachingAgeSum As Integer
RecordNumber = 1: TeachingAgeMax = 0: TeachingAgeMin = 100
Open "D:\Teacher.dat" For Random As #1 Len = Len(Teac)
For RecordNumber = 1 To LOF(1) / Len(Teac)
Get #1, RecordNumber, Teac
TeachingAgeSum = TeachingAgeSum + Teac.TeachingAge
If Teac.TeachingAge > TeachingAgeMax Then TeachingAgeMax = Teac.TeachingAge
If Teac.TeachingAge < TeachingAgeMin Then TeachingAgeMin = Teac.TeachingAge
Next RecordNumber
Picture1.Print
Picture1.Print " 教师的最长教龄为:" & TeachingAgeMax & "年"
Picture1.Print " 教师的最短教龄为:" & TeachingAgeMin & "年"
Picture1.Print " 教师的平均教龄为:" & TeachingAgeSum / (LOF(1) / Len(Teac)) & "年"
Close #1
End Sub
Private Sub Return_Click()
Load Form1
Form1.Show
Unload Form2
End Sub
窗体1菜单:
窗体2菜单:
运行界面:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询