假设我在VBA中有这个数组:
a(0) = 1
a(1) = f
a(2) = g
a(3) = 4
.
..
..
a(k) = a
我想在(0)处插入一个新值,并将每个值下移一个索引,如下所示。
a(0) = newVal
a(1) = 1
a(2) = f
a(3) = g
a(4) = 4
.
..
..
a(k+1) = a
有没有简便的代码实现方式?如果没有,最快的方法是什么?
我可以用简单的for循环来实现,但我想知道是否有更有效率的方式?
例如,这是我能想到的:
Dim temp()
Redim Preserve temp(0)
temp(0) = "newVal"
For i= lbound(a) + 1 to ubound(a) + 1
redim preserve temp(i)
temp(i) = a(i-1)
Next i