主题:下标越界问题,高手帮帮忙
xiaokiss2008
[专家分:0] 发布于 2013-02-17 10:49:00
Do While Not EOF(1)
Line Input #1, a
s = Replace(a, vbTab, " ")
c = Split(s, " ")
ReDim f(1, UBound(c))
For n = 0 To UBound(c)
f(m, n) = c(n)
Next n
m = m + 1
Loop
这里为什么在我加了一个外层循环f(m,n)=c(n)就会出现下标越界,但是去掉外层循环就不会下标越界,高手们帮我看看,谢谢你们了
回复列表 (共4个回复)
沙发
老大徒伤悲 [专家分:29120] 发布于 2013-02-17 21:08:00
因为
m = m + 1
被多次执行,超过1,就会出现
f(2,……)
当然下标越界
板凳
xiaokiss2008 [专家分:0] 发布于 2013-02-18 12:33:00
Do While Not EOF(1)
Line Input #1, a
s = Replace(a, vbTab, " ")
c = Split(s, " ")
ReDim f(m, UBound(c))
For n = 0 To UBound(c)
f(m, n) = c(n)
Next n
m = m + 1
Loop
我把程序这里改了ReDim f(m, UBound(c)) ,确实不报错了,但是为什么f(m,n)只有数据的最后一行,前面的数据都没,纠结啊,帅哥再帮我看看
3 楼
xiaokiss2008 [专家分:0] 发布于 2013-02-18 12:35:00
Do While Not EOF(1)
Line Input #1, a
s = Replace(a, vbTab, " ")
c = Split(s, " ")
ReDim f(m, UBound(c))
For n = 0 To UBound(c)
f(m, n) = c(n)
Next n
m = m + 1
Loop
上面那个程序没法好 看这个了
4 楼
xiaokiss2008 [专家分:0] 发布于 2013-02-18 12:37:00
Do While Not EOF(1)
Line Input #1, a
s = Replace(a, vbTab, " ")
c = Split(s, " ")
ReDim f(m, UBound(c))
For n = 0 To UBound(c)
f(m, n) = c(n)
Next n
m = m + 1
Loop
我把程序这里改了ReDim f(m, UBound(c)) ,确实不报错了,但是为什么f(m,n)只有数据的最后一行,前面的数据都没,纠结啊,帅哥再帮我看
我来回复