我是个初学者,最头大的问题是,vb中数组的下标越界问题。
哪位高手高手高高手能提供一个全面的解决方案啊??
希望结交高手。帮助我学习,等我成为高手了大家交流。本人qq:58203777
救人一命胜。。。
Dim tech() As teacher
Dim n As Integer, curi As Integer
Private Sub xianshi(ByVal X As Integer)
Text1.Text = tech(X).name
Text2.Text = tech(X).rq
Combo1.Text = tech(X).prof
Option1(0).Value = tech(X).sex
Combo2.Text = tech(X).nation
Text3.Text = tech(X).salary
HScroll1.Value = tech(X).lang
Text5.Text = tech(X).history
Text4.Text = tech(X).depart
End Sub
Private Sub Combo1_Click()
tech(curi).prof = Combo1.Text
End Sub
Private Sub Combo2_Click()
tech(curi).nation = Combo2.Text
End Sub
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0
curi = curi - 1
If curi <= 0 Then curi = 1
xianshi (curi)
Case 1
If curi > n Then curi = n
xianshi (curi)
Case 2
Command1(0).Enabled = True
Command1(1).Enabled = True
Command1(3).Enabled = True
Command1(4).Enabled = True
n = n + 1
ReDim Preserve tech(n) As teacher
curi = n
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Combo1.Text = ""
Combo2.Text = ""
HScroll1.Value = 0
Option1(0).Value = True
With tech(curi)
.name = "": .depart = "": .history = "": .lang = 0
.nation = ""
.prof = ""
.rq = ""
.salary = 0
.sex = True
Text1.SetFocus
End With
Case 3
If MsgBox("真要删除当前教师记录吗?", 36, "信息提示") = 6 Then
n = n - 1
If n = 0 Then
Command1(0).Enabled = False
Command1(1).Enabled = False
Command1(3).Enabled = False
Command1(4).Enabled = False
Exit Sub
End If
If curi = n + 1 Then Exit Sub
For i = curi To n
tech(i).name = tech(i + 1).name
tech(i).depart = tech(i + 1).depart
tech(i).salary = tech(i + 1).salary
tech(i).history = tech(i + 1).history
tech(i).prof = tech(i + 1).prof
tech(i).sex = tech(i + 1).sex
tech(i).nation = tech(i + 1).nation
tech(i).lang = tech(i + 1).lang
tech(i).rq = tech(i + 1).rq
Next i
curi = curi - 1
xianshi (curi)
End If
Case 4
i = InputBox("请输入记录号(1-" + Trim(Str(n)) + ")", "数据输入", "1")
If i <= n And i > 0 Then
curi = i
xianshi (curi)
End If
End Select
End Sub
Private Sub Form_Load()
With Combo2
.AddItem "汉族", 0
.AddItem "回族", 1
.AddItem "满族", 2
.AddItem "蒙古族", 3
End With
With Combo1
.AddItem "教授", 0
.AddItem "副教授", 1
.AddItem "讲师", 2
.AddItem "助教", 3
End With
Command1(0).Enabled = False
Command1(1).Enabled = False
Command1(3).Enabled = False
Command1(4).Enabled = False
n = 0
End Sub
Private Sub Option1_Change(Index As Integer)
tech(curi).sex = Option1(0).Value
End Sub
Private Sub HScroll1_Change()
tech(curi).lang = HScroll1.Value
End Sub
Private Sub Text1_Change()
tech(curi).name = Text1.Text
End Sub
Private Sub Text2_Change()
tech(curi).rq = Text2.Text
End Sub
Private Sub Text3_Change()
tech(curi).salary = Val(Text3.Text)
End Sub
Private Sub Text4_Change()
tech(curi).depart = Text4.Text
End Sub
Private Sub Text5_Change()
tech(cur).history = Text5.Text
End Sub