EXCEL高手用VBA解释一下FOR循环数组AI输

高手们,打扰一下,EXCEL高手用VBA解释一下FOR循环数组AI输?

sub subp(b() as integer)
for i=1 to 4
b(i)=2*i
next i
end sub

private sub command1_click()
dim a(1 to 4) as integer
a(1)=5
a(2)=6
a(3)=7
a(4)=8
subp a()
print a(i)
for i=1 to 4
print a(i)
next i
end sub

结果为(A)

A,2
4
6
8

B,5
6
7
8

C,10
12
14
16

D,出错

书本上答案A,编译出错,这个究竟哪里错了请指导
最新回答
梦幻樱雪

2024-04-27 08:32:17

sub subp(b() as integer)
for i=1 to 4
b(i)=2*i
next i
end sub

private sub command1_click()
dim a(1 to 4) as integer
a(1)=5
a(2)=6
a(3)=7
a(4)=8
subp a()
print a(i)'多了这一句,这里i=0,a(0)下标越界
for i=1 to 4
print a(i)
next i
end sub