2013-09-26 190 views
0

我有一個動態的陣列,其中該陣列的尺寸的變化,根據在數據庫中的節數的行 碼是這樣的:任何快捷方法重新初始化陣列在vb.net

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 

是否有任何單行代碼或任何短手操作來重新初始化數組

回答

0

不能完全確定我已經明白將q但是....

不知道這是正確的做法,但我始終REDIM,因爲我去這樣的代碼會看起來像這樣:

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) 
+0

僅僅是明確@codebits你是不是每次redimension數組,但只需要設定其所有元素爲0? – OSKM

+0

是的,我想重置數組元素爲'0'\零 – Codebits

+0

在這種情況下,您的方法是我所知道的最好的。 – OSKM

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