大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
实验8-7
在教学篇例8.7的基础上增加“修改确定”按钮以及用于定位记录的按钮面板,如图2.8.5所示,并编写时间过程。
解题,代码如下:
先建立标准模块,代码是:
Type studtype
iNo As Integer
strName As String * 20
strSex As String * 1
sMark As Single
End Type
再在窗体上建立相应的按钮等控件,窗体代码如下:
Dim Student As studtype
Dim Record_No As Integer
Sub Form_Load()
Open “C:\STUDENT.DAT” For Random As #1 Len = Len(Student)
Label1.Caption = LOF(1) / Len(Student)
Close #1
If Label1.Caption <> “0” Then Command3_Click ‘记录不为零,就显示第一条记录
End Sub
Sub Command1_Click() ‘追加记录
With Student
.iNo = Val(Text1.Text)
.strName = Text2.Text
.strSex = IIf(Option1.Value, “1”, “0”)
.sMark = Val(Text3.Text)
End With
Open “C:\STUDENT.DAT” For Random As #1 Len = Len(Student)
Record_No = LOF(1) / Len(Student) + 1
Label1.Caption = Record_No
Text4.Text = Record_No ‘加这句,当场修改记录就不用手工输入了
Put #1, Record_No, Student
Close #1
End Sub
Sub Command2_Click() ‘显示记录
Open “C:\STUDENT.DAT” For Random As #1 Len = Len(Student)
Record_No = Val(Text4.Text)
Get #1, Record_No, Student
Text1.Text = Student.iNo
Text2.Text = Student.strName
If Student.strSex = “1” Then
Option1.Value = True
Else
Option2.Value = True
End If
Text3.Text = Student.sMark
Record_No = LOF(1) / Len(Student)
Close #1
End Sub
Private Sub Command3_Click() ‘第一条记录
Open “C:\STUDENT.DAT” For Random As #1 Len = Len(Student)
Record_No = 1
Get #1, Record_No, Student
Text1.Text = Student.iNo
Text2.Text = Student.strName
If Student.strSex = “1” Then
Option1.Value = True
Else
Option2.Value = True
End If
Text3.Text = Student.sMark
Text4.Text = “1”
Close #1
End Sub
Private Sub Command4_Click() ‘下一条记录
If Record_No = Val(Label1.Caption) Then
MsgBox “已经是最后一条记录了”
Exit Sub ‘已经是最后一条记录就退出。
End If
Open “C:\STUDENT.DAT” For Random As #1 Len = Len(Student)
Record_No = Record_No + 1
Get #1, Record_No, Student
Text1.Text = Student.iNo
Text2.Text = Student.strName
If Student.strSex = “1” Then
Option1.Value = True
Else
Option2.Value = True
End If
Text3.Text = Student.sMark
Text4.Text = Record_No
Close #1
End Sub
Private Sub Command5_Click() ‘前一条记录
If Record_No = 1 Then
MsgBox “已经是第一条记录了”
Exit Sub ‘已经是第一条记录就退出。
End If
Open “C:\STUDENT.DAT” For Random As #1 Len = Len(Student)
Record_No = Record_No – 1
Get #1, Record_No, Student
Text1.Text = Student.iNo
Text2.Text = Student.strName
If Student.strSex = “1” Then
Option1.Value = True
Else
Option2.Value = True
End If
Text3.Text = Student.sMark
Text4.Text = Record_No
Close #1
End Sub
Private Sub Command6_Click() ‘最后一条记录
Open “C:\STUDENT.DAT” For Random As #1 Len = Len(Student)
Record_No = Val(Label1.Caption)
Get #1, Record_No, Student
Text1.Text = Student.iNo
Text2.Text = Student.strName
If Student.strSex = “1” Then
Option1.Value = True
Else
Option2.Value = True
End If
Text3.Text = Student.sMark
Text4.Text = Label1.Caption
Close #1
End Sub
Sub Command7_Click() ‘修改记录
With Student
.iNo = Val(Text1.Text)
.strName = Text2.Text
.strSex = IIf(Option1.Value, “1”, “0”)
.sMark = Val(Text3.Text)
End With
Open “C:\STUDENT.DAT” For Random As #1 Len = Len(Student)
Record_No = Val(Text4.Text)
Put #1, Record_No, Student
Close #1
End Sub
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/185047.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...