求VB答案呀 急急急!!!!(主编 王国权) 清华大学出版社 20
全部方法和代码:
在窗体上添加5个label,3个text和4个command,设置label1的caption为“姓名”,对应text1;label2设置为“专业”对应text2;label3设置为“总分”,对应text3,lebel4为“位置”,label5用来显示目前所在的位置(具体如以下的图:)。代码如下:
Private Type student
xm As String * 6
zy As String * 10
zf As Single '字符串长度自己定
End Type
Dim st(1 To 100) As student
Dim n As Integer, i As Integer, t As Integer
Private Sub Command1_Click() '新增
If n > 100 Then
MsgBox "记录数已满!"
Else
n = n + 1
t = t + 1
st(n).xm = CStr(Text1.Text)
st(n).zy = CStr(Text2.Text)
st(n).zf = Val(Text3.Text)
Label5.Caption = n & "/" & n
End If
End Sub
Private Sub Command2_Click() '前一个
If n = 1 Then
MsgBox "目前只有一条记录,无法查看前一个!"
ElseIf n = 0 Then
MsgBox "无记录,无法查看!"
Else
If t - 1 > 0 Then
t = t - 1
Text1.Text = st(t).xm
Text2.Text = st(t).zy
Text3.Text = st(t).zf
Label5.Caption = t & "/" & n
Else
MsgBox "已经是最前一个了"
End If
End If
End Sub
Private Sub Command3_Click() '后一个
If n = 1 Then
MsgBox "目前只有一条记录,无法查看后一个!"
ElseIf n = 0 Then
MsgBox "无记录,无法查看!"
Else
If t + 1 <= n Then
t = t + 1
Text1.Text = st(t).xm
Text2.Text = st(t).zy
Text3.Text = st(t).zf
Label5.Caption = t & "/" & n
Else
MsgBox "已经是最后一个了"
End If
End If
End Sub
Private Sub Command4_Click() '最高
Max = st(1).zf
For i = 1 To n
Max = IIf(Max >= st(i).zf, Max, st(i).zf)
Next
For i = 1 To n
If st(i).zf = Max Then
t = i
Text1.Text = st(t).xm
Text2.Text = st(t).zy
Text3.Text = st(t).zf
Label5.Caption = t & "/" & n
End If
Next
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Label5.Caption = t & "/" & n
End Sub