vb下标越界。急啊···

发布网友 发布时间:2024-10-24 07:04

我来回答

3个回答

热心网友 时间:2024-10-24 08:39

当你完成
For i = 1 To 10
If a(i) > aver Then
End If
时,i=11了, a(i)下标越界

Option Base 1
Private Sub Form_Click()
Dim a(10) As Integer, aver!, sum As Integer
For i = 1 To 10
a(i) = Int(Rnd * 90 + 10)
sum = sum + a(i)
Print a(i);
If i Mod 5 = 0 Then Print
Next
aver = sum / 10
Print "平均成绩为:"; aver
For i = 1 To 10
If a(i) > aver Then Print "正整数是:"; a(i)
Next

End Sub

热心网友 时间:2024-10-24 08:40

a(10)代表的是0到9,而不是1到10.
把for i=1 to 10改为 fro i=0 to 9

热心网友 时间:2024-10-24 08:41

Option Base 1

Private Sub Form_Click()
Dim a(10) As Integer, aver, sum As Integer
For i = 1 To 10
a(i) = Int(Rnd * 90 + 10)
sum = sum + a(i)
Print a(i);
If i Mod 5 = 0 Then Print
Next
aver = sum / 10
For i = 1 To 10
If a(i) > aver Then
Print "正整数是:"; a(i)
End If
Next
Print "平均成绩为:"; aver

End Sub

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com