谢谢了 我在编写一个学生信息系统 编译时,出现了错误,大家帮忙啊。 代码如下: '定义类型 Private Type studType No As Integer Name As String * 10 Sex As Boolean Rq As Data Mz As String * 12 Class As String * 5 End Type Dim student As studType Dim Recs As Integer '文件中记录总个数 Dim CurNo As Integer Dim Op As Integer Private Sub Exit_Click() Open "student1.dat" For Random As #2 Len = Len(student) For i = 1 To Recs Get #1, i, student Put #2, i, student Next Close Kill "student.dat" Name "student1.dat" As "student.dat" End Sub Private Sub Form_Load() Picture2.Visible = False Open "student.dat" For Random As #1 Len = Len(student) Recs = LOF(1) / Len(student) If Recs > 0 Then CurNo = 1 BEnabled (True) DispRec Else CurNo = 0 BEnabled (False) TxtEnabled (False) End If End SubPrivate Sub Tp_Click(Index As Integer) CurNo = 1 DispRec End Sub Private Sub Prev_Click(Index As Integer) CurNo = CurNo - 1 If CurNo < 1 Then CurNo = 1 DispRec End Sub
Private Sub Nex_Click(Index As Integer) CurNo = CurNo + 1 If CurNo > Recs Then CurNo = Recs DispRec End Sub Private Sub Bott_Click(Index As Integer) CurNo = Recs DispRec End Sub Private Sub Add_Click(Index As Integer) labOp.Caption = "添加记录" BEnabled (True) Op = 1 txtNo.Text = "" txtName.Text = "" optSex(0).Value = True comMz .Text = "" txtRq.Text = "" txtClass.Text = "" TxtEnabled (True) Picture1.Visible = False Picture2.Visible = True End SubPrivate Sub Upd_click(Index As Integer) labOp.Caption = "修改记录" Op = 2 TxtEnabled (True) Picture1.Visible = False Picture2.Visible = True End Sub Private Sub Del_Click(Index As Integer) labOp.Caption = "删除记录" Op = 2 Picture1.Visible = False Picture2.Visible = True End Sub Private Sub Ok_click(Index As Integer) Picture1.Visible = True Picture2.Visible = False If Op = 1 Then '添加确定 Recs = Recs + 1 CurNo = Recs WriteRec ElseIf Op = 2 Then WriteRec ElseIf Op = 3 Then i = CurNo Do While i < Recs Get #1, i + 1, student Put #1, i, student i = i + 1 Loop Recs = Recs - 1 student.No = Empty student.Name = "" student.Sex = Empty student.Mz = "" student.Rq = Empty student.Class = "" Put #1, i, student If Recs = 0 Then txtNo.Text = "" txtName.Text = "" optSex(0).Value = True comMz.Text = "" txtRq.Text = "" txtClass.Text = "" BEnabled (False) Else CurNo = CurNo - 1 DispRec End If End If End Sub Private Sub Cancel_Click(Index As Integer) Picture1.Visible = True Picture2.Visible = False If Recs = 0 Then txtNo.Text = "" txtName.Text = "" optSex(0).Value = True comMz.Text = "" txtRq.Text = "" txtClass.Text = "" BEnabled (False) Else DispRec End If End SubPrivate Sub DispRec() Get #1, CurNo, student txtNo.Text = student.No txtName.Text = student.Name If student.Sex = True Then optSex(0).Value = True Else optSex(1).Value = True End If comMz.Text = student.Mz txtRq.Text = student.Rq txtClass.Text = student.Class TxtEnabled (False) Picture2.Visible = False End Sub Private Sub WriteRec() student.No = Val(txtNo.Text) student.Name = txtName.Text If optSex(0) Then student.Sex = True Else student.Sex = False End If student.Mz = comMz.Text If txtRq.Text = "" Then student.Rq = Empty Else student.Rq = txtRq.Text End If student.Class = txtClass.Text Put #1, CurNo, student End Sub Private Sub BEnabled(ByVal setvalue As Boolean) Tp.Enabled = setvalue Prev.Enabled = setvalue Nex.Enabled = setvalue Bott.Enabled = setvalue Del.Enabled = setvalue Upd.Enabled = setvalue End Sub Private Sub TxtEnabled(ByVal setvalue As Boolean) txtNo.Enabled = setvalue txtName.Enabled = setvalue optSex(0).Enabled = setvalue optSex(1).Enabled = setvalue txtRq.Enabled = setvalue comMz.Enabled = setvalue txtClass.Enabled = setvalue End Sub
Private Sub Tp_Click(Index As Integer)End Sub ??? Tp.Enabled = setvalue Prev.Enabled = setvalue Nex.Enabled = setvalue Bott.Enabled = setvalue Del.Enabled = setvalue Upd.Enabled = setvalue???你有多个TP按钮吗? 把Index As Integer去掉
自定义中 Private Type studType No As Integer Name As String * 10 Sex As Boolean Rq As Data Mz As String * 12 Class As String * 5 End Type 由于Class在VB中是类的定义,不能用Class作为变量. 把Class改为其他变量名。
我在编写一个学生信息系统
编译时,出现了错误,大家帮忙啊。
代码如下:
'定义类型 Private Type studType
No As Integer
Name As String * 10
Sex As Boolean
Rq As Data
Mz As String * 12
Class As String * 5
End Type
Dim student As studType
Dim Recs As Integer '文件中记录总个数
Dim CurNo As Integer
Dim Op As Integer
Private Sub Exit_Click()
Open "student1.dat" For Random As #2 Len = Len(student)
For i = 1 To Recs
Get #1, i, student
Put #2, i, student
Next
Close
Kill "student.dat"
Name "student1.dat" As "student.dat"
End Sub Private Sub Form_Load()
Picture2.Visible = False
Open "student.dat" For Random As #1 Len = Len(student)
Recs = LOF(1) / Len(student)
If Recs > 0 Then
CurNo = 1
BEnabled (True)
DispRec
Else
CurNo = 0
BEnabled (False)
TxtEnabled (False)
End If
End SubPrivate Sub Tp_Click(Index As Integer)
CurNo = 1
DispRec
End Sub
Private Sub Prev_Click(Index As Integer)
CurNo = CurNo - 1
If CurNo < 1 Then CurNo = 1
DispRec
End Sub
Private Sub Nex_Click(Index As Integer)
CurNo = CurNo + 1
If CurNo > Recs Then CurNo = Recs
DispRec
End Sub
Private Sub Bott_Click(Index As Integer)
CurNo = Recs
DispRec
End Sub
Private Sub Add_Click(Index As Integer)
labOp.Caption = "添加记录"
BEnabled (True)
Op = 1
txtNo.Text = ""
txtName.Text = ""
optSex(0).Value = True
comMz .Text = ""
txtRq.Text = ""
txtClass.Text = ""
TxtEnabled (True)
Picture1.Visible = False
Picture2.Visible = True
End SubPrivate Sub Upd_click(Index As Integer)
labOp.Caption = "修改记录"
Op = 2
TxtEnabled (True)
Picture1.Visible = False
Picture2.Visible = True
End Sub
Private Sub Del_Click(Index As Integer)
labOp.Caption = "删除记录"
Op = 2
Picture1.Visible = False
Picture2.Visible = True
End Sub
Private Sub Ok_click(Index As Integer)
Picture1.Visible = True
Picture2.Visible = False
If Op = 1 Then '添加确定
Recs = Recs + 1
CurNo = Recs
WriteRec
ElseIf Op = 2 Then
WriteRec
ElseIf Op = 3 Then
i = CurNo
Do While i < Recs
Get #1, i + 1, student
Put #1, i, student
i = i + 1
Loop
Recs = Recs - 1
student.No = Empty
student.Name = ""
student.Sex = Empty
student.Mz = ""
student.Rq = Empty
student.Class = ""
Put #1, i, student
If Recs = 0 Then
txtNo.Text = ""
txtName.Text = ""
optSex(0).Value = True
comMz.Text = ""
txtRq.Text = ""
txtClass.Text = ""
BEnabled (False)
Else
CurNo = CurNo - 1
DispRec
End If
End If
End Sub
Private Sub Cancel_Click(Index As Integer)
Picture1.Visible = True
Picture2.Visible = False
If Recs = 0 Then
txtNo.Text = ""
txtName.Text = ""
optSex(0).Value = True
comMz.Text = ""
txtRq.Text = ""
txtClass.Text = ""
BEnabled (False)
Else
DispRec
End If
End SubPrivate Sub DispRec()
Get #1, CurNo, student
txtNo.Text = student.No
txtName.Text = student.Name
If student.Sex = True Then
optSex(0).Value = True
Else
optSex(1).Value = True
End If
comMz.Text = student.Mz
txtRq.Text = student.Rq
txtClass.Text = student.Class
TxtEnabled (False)
Picture2.Visible = False
End Sub
Private Sub WriteRec()
student.No = Val(txtNo.Text)
student.Name = txtName.Text
If optSex(0) Then
student.Sex = True
Else
student.Sex = False
End If
student.Mz = comMz.Text
If txtRq.Text = "" Then
student.Rq = Empty
Else
student.Rq = txtRq.Text
End If
student.Class = txtClass.Text
Put #1, CurNo, student
End Sub
Private Sub BEnabled(ByVal setvalue As Boolean)
Tp.Enabled = setvalue
Prev.Enabled = setvalue
Nex.Enabled = setvalue
Bott.Enabled = setvalue
Del.Enabled = setvalue
Upd.Enabled = setvalue
End Sub
Private Sub TxtEnabled(ByVal setvalue As Boolean)
txtNo.Enabled = setvalue
txtName.Enabled = setvalue
optSex(0).Enabled = setvalue
optSex(1).Enabled = setvalue
txtRq.Enabled = setvalue
comMz.Enabled = setvalue
txtClass.Enabled = setvalue
End Sub
???
Tp.Enabled = setvalue
Prev.Enabled = setvalue
Nex.Enabled = setvalue
Bott.Enabled = setvalue
Del.Enabled = setvalue
Upd.Enabled = setvalue???你有多个TP按钮吗?
把Index As Integer去掉
Private Type studType
No As Integer
Name As String * 10
Sex As Boolean
Rq As Data
Mz As String * 12
Class As String * 5
End Type
由于Class在VB中是类的定义,不能用Class作为变量.
把Class改为其他变量名。