我的vb程序运行时下标越界了,求高手帮忙指点一下!!

来源:百度知道 编辑:UC知道 时间:2024/06/07 04:57:28
Dim a, i%
a = Array(1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25)
n = UBound(a)
x = Val(InputBox("要删除的数值为"))
For i = 0 To n
If x = a(i) Then Exit For
Next i
k = i
For i = k To n - 1
a(i) = a(n + 1)
Next i
ReDim Preserve a(n - 1)
End Sub

a(i) = a(n + 1)这里你不能这么写啊,这个数组需要重新定义
redim Preserve a(n+1)
也不对,你是要删除的
应该是
For i = k To n - 1
a(i) = a(i + 1)
Next i
ReDim Preserve a(n - 1)