日期:2014-05-17  浏览次数:20743 次

如果数组A有5个元素,数组B有3个元素,for i=0 to Ubound(A);x = A(i);y=B(i) ;则就会出现数组越界的问题,r如何解决呀?


是的,如果数组A有5个元素,数组B有3个元素。
那么
for i=0 to Ubound(A)
x = A(i)
y=B(i)  

则就会出现数组越界的问题

是呀,如何解决这个问题呀?

------解决方案--------------------
方法1

for i=0 to Ubound(B)
x = A(i)
y=B(i) 
Next

方法2

for i=0 to Ubound(A)
x = A(i)
If i <= Ubound(B) Then
y=B(i) 
Else
y = ""
End If
Next
------解决方案--------------------
on error resume next,不过孟子E章的方法更好些