VB中提示我下标越界,怎么回事啊?怎么改呢?谢谢啦~

PrivateSubForm_Click()Dima()AsInteger,b()AsSingle,nAsInteger,sumAsInteger,averAsSingl... Private Sub Form_Click()
Dim a() As Integer, b() As Single, n As Integer, sum As Integer, aver As Single
Dim max As Integer, min As Integer, k As Integer, s As Integer, m As Integer
n = InputBox("输入学生人数")
ReDim a(1 To n)
ReDim b(1 To n)
sum = 0
For i = 1 To n
a(i) = InputBox("输入第" & i & "个学生的成绩")
b(i) = InputBox("输入第" & i & "个学生的学号")
sum = sum + a(i)
Next
aver = sum / n
max = a(1)
min = a(1)
For i = 2 To n
If max < a(i) Then
max = a(i)
k = i
End If
If min > a(i) Then
min = a(i)
s = i
End If
Next

Print "总分" & sum
Print "平均分" & aver
Print "最高分" & a(k) & "学号" & b(k)
Print "最低分" & a(s) & "学号" & b(s)

For i = 1 To n
If a(i) > aver Then
Print a(i)
End If
Next
End Sub
展开
 我来答
tonkeys
2013-05-04 · TA获得超过1513个赞
知道大有可为答主
回答量:2087
采纳率:33%
帮助的人:2436万
展开全部
Private Sub Form_Click()
Dim a() As Integer, b() As Single, n As Integer, sum As Integer, aver As Single
Dim max As Integer, min As Integer, k As Integer, s As Integer, m As Integer
n = InputBox("输入学生人数")
ReDim a(1 To n)
ReDim b(1 To n)
sum = 0
For i = 1 To n
a(i) = InputBox("输入第" & i & "个学生的成绩")
b(i) = InputBox("输入第" & i & "个学生的学号")
sum = sum + a(i)
Next
aver = sum / n
max = a(1)
min = a(1)
s = 1 '<========这里增加的
k = 1 '<========这里增加的
For i = 2 To n
If max < a(i) Then
max = a(i)
k = i
End If
If min > a(i) Then
min = a(i)
s = i
End If
Next

Print "总分" & sum
Print "平均分" & aver
Print "最高分" & a(k) & "学号" & b(k)
Print "最低分" & a(s) & "学号" & b(s)

For i = 1 To n
If a(i) > aver Then
Print a(i)
End If
Next
End Sub
tf日出
2013-05-04 · TA获得超过1076个赞
知道小有建树答主
回答量:648
采纳率:0%
帮助的人:259万
展开全部
max = a(1)
min = a(1)
后面添两句
k=1:s=1
试试,如果第一个就是最大的或最小的,那么运行完后K=0或S=0,所以要加下这两句。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式