求解,为何此处会“索引超出了数组界限”,最近考VB,感激不尽!
Dima(19)AsInteger,bAsInteger,cAsInteger,dAsInteger,gAsIntegerd=0g=0c=0Forb=0To19a(b)=...
Dim a(19) As Integer, b As Integer, c As Integer, d As Integer, g As Integer
d = 0
g = 0
c = 0
For b = 0 To 19
a(b) = Int(Rnd() * 100)
Next b
Do While c < 20
c = c + 1
If a(c) > 50 Then d = d + 1 ‘索引超出了数组界限
If a(c) < 10 Then g = g + 1
Loop
MsgBox("在50万元以上的有" & Str(d) & " " & "在10万元以下的有" & Str(g))
End Sub 展开
d = 0
g = 0
c = 0
For b = 0 To 19
a(b) = Int(Rnd() * 100)
Next b
Do While c < 20
c = c + 1
If a(c) > 50 Then d = d + 1 ‘索引超出了数组界限
If a(c) < 10 Then g = g + 1
Loop
MsgBox("在50万元以上的有" & Str(d) & " " & "在10万元以下的有" & Str(g))
End Sub 展开
1个回答
展开全部
do while c<20后,你把c加1了,也就是c=19时,那到if a(c)这会,c就是20了,超过了a的下下标。可以把c放在if后面
Dim a(19) As Integer, b As Integer, c As Integer, d As Integer, g As Integer
d = 0
g = 0
c = 0
For b = 0 To 19
a(b) = Int(Rnd() * 100)
Next b
Do While c < 20
If a(c) > 50 Then d = d + 1 ‘索引超出了数组界限
If a(c) < 10 Then g = g + 1
c = c + 1
Loop
MsgBox("在50万元以上的有" & Str(d) & " " & "在10万元以下的有" & Str(g))
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询