VB下标越界,看看我这段代码哪里有错?

2025-01-03 16:37:39
推荐回答(3个)
回答1:

b(k)=a(i),此时i=10
Private Sub Form_Load()
Show
Dim a(9) As Integer, b(9) As Integer
For i = 0 To 9
a(i) = InputBox("请输入10个整数")
Print a(i);
Next i
Print
For i = 9 To 0 Step -1
k = 9 - i
b(k) = a(i)
Print b(k);
Next i
End Sub

回答2:

b(k) = a(i)
i = 10
当然越界。

回答3:

For i = 0 To 9
a(i) = InputBox("请输入10个整数")
k = 9 - i
Print a(i);
Next i
当循环结束时i的值是10,再运行下一句b(k)=a(i)时,就变成了a(10),数组下标越界。。。