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 展开
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 展开
2个回答
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询