比較一下程式哪個跑的快?
(1). redim A(1 to 8,1 to 1000000)
……
p=p+1
…….
redim preserve A(1 to 8,1 to p)
(2). redim A(1 to 8,1 to p)
……
p=p+1
…….
redim preserve A(1 to 8,1 to p)
(3). A=[a1:h25000]:d as new dictionary
for i=1 to ubound(a,1)
d(a(i,1))=array(a(i,4),a(i,5),a(i,3),a(i,2),a(i,6),a(i,7),)
next i
(4). A=[a1:h25000]:d as new dictionary
for i=1 to ubound(a,1)
d(a(i,1))=application.index(A,I,array(a(i,4),a(i,5),a(i,3),a(i,2),a(i,6),a(i,7),)
next i
測試結果:
(1)比(2),寫起來容易,不用太多考慮,先redim數組足夠大,用了多少再redim preserve A(1 to 8, 1 to 真正需要的P)
(3)比(4),寫起來既直觀又容易,而且速度快250倍!