0

我有一个动态数组,其中数组大小根据数据库代码中的行数而变化,如下所示:

Dim pgm_act_arr(0) As Double
Dim pgm_act_count As Integer = no.of rows retuned from database
ReDim pgm_act_arr(pgm_act_count)


for each rows in database1
'i want to reinitialize the array here
'now am using for loop to reinitialize array to zero
For i As double to pgm_act_arr.Length
pgm_act_arr(i) = 0.0
Next

for each rows in database2
pgm_act_arr(index)+=somevalue 'inserting values to array elements
next

next 

是否有任何单行代码或任何速记操作来重新初始化数组

4

2 回答 2

0

不完全确定我已经理解了 Q 但是....

不确定这是否是正确的方法,但我总是边走边改,所以代码看起来像这样:

Dim pgm_act_arr(0) As Double

for each rows in database2
    pgm_act_arr(index)+=somevalue 'inserting values to array elements
    ReDim preserve pgm_act_arr(ubound(pgm_act_arr)+1)
next
'remove blank entry at bottom
ReDim preserve pgm_act_arr(ubound(pgm_act_arr)-1)

将阵列重置为开始时

ReDim pgm_act_arr(0)
于 2013-09-26T14:55:28.393 回答
0

所以考虑数组大小为 3 即

pgm_act_arr(0)=1
pgm_act_arr(1)=2
pgm_act_arr(2)=3

所以我想做的是

pgm_act_arr(0)=0
pgm_act_arr(1)=0
pgm_act_arr(2)=0

但据我所知,这是最简单的方法

for i=0 to 2
  pgm_act_arr(i)=0.0
next
于 2013-09-27T04:43:49.653 回答