一个关于vb自定义类型数组应用的问题。。

来源:百度知道 编辑:UC知道 时间:2024/06/17 08:15:34
Private Type studtype
name As String * 10
special As String * 10
total As Single
End Type

Private Sub Command1_Click(Index As Integer)
Dim stud(1 To 100) As studtype, n%, i%, max!, maxi%, j%
Select Case Index
Case 0
If n < 100 Then
n = n + 1
i = n
stud(n).name = Text1
stud(n).special = Text2
stud(n).total = Val(Text3)
Text1 = ""
Text2 = ""
Text3 = ""
Else
MsgBox "输入人数超过数组声明的个数"
End
End If
Case 1
If i > 1 Then i = i - 1

Text1 = stud(i).name
Text2 = stud(i).special
Text3 = stud(i).total

Case 2
If i < n Then i = i + 1

Text1 = stud(i).name
Text2 = stud(i).special
Text3 = stud(i).total

Case 3
max = stud(1).total

不知道你的具体出错情况是什么~~大概看了一下~

你声明的 n% 是用来保存人数的~~
但是你把 n% 给放到了Command1_Click 的事件里了~
变量 n% 的生存周期在 Command1_Click 结束后就消失了~
所以 n% 应该声明称静态变量 static n%

o