0

I have a dynamic array ,where the array size changes according to the no.of rows in database code goes like this :

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 

Is there any single line code or any short hand operations to reinitialise the array

Shivachandra
  • 93
  • 2
  • 8

2 Answers2

0

Not entirely sure i have understood the Q but....

Not sure if it is the right way but i always redim as i go so code would look like this:

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)

To reset the array to as it started

ReDim pgm_act_arr(0)
OSKM
  • 728
  • 14
  • 25
  • just to be clear @codebits you are not looking to redimension the array each time but simply set all its elements to 0? – OSKM Sep 27 '13 at 05:25
  • in which case your method above is the best i know. – OSKM Oct 01 '13 at 15:15
  • am using the array to store the commission amount and due to the horizontal and vertical arrangements of the policy details in 2 different table and a vertical table which is commission master it has become a complex structure to carry out commission – Shivachandra Oct 02 '13 at 04:29
0

So consider array size as 3 i.e.

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

so what i want to do is

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

But as far as i know this is the simplest way

for i=0 to 2
  pgm_act_arr(i)=0.0
next
Shivachandra
  • 93
  • 2
  • 8