G
Guest
Hello all,
I want to perform the following task:
1. Create an array
2. Fill it up (number of elements unknown in advance)
3. Iterate through it using For Each loop (cannot do this in the in the
previous step)
I ended up with something like this:
1 Dim arr()
2 ReDim arr(0)
3 Do While <Loop Condition>
4 'Data acquisition here
5 ReDim Preserve arr(UBound(arr,1) + 1)
6 arr(UBound(arr,1) - 1) = theData
7 Loop
8 ReDim Preserve arr(UBound(arr,1) -1)
...
9 For Each item In arr
10 'First data processing here
11 Next
...
12 For Each item In arr
13 'Second data processing here
14 Next
What I don't like:
- Have to redim every time a data is added to the array (line 5)
- Must have a dummy element (line 2) to make UBound happy
- Must drop the dummy element to make my for each simpler (line 8)
- Indices are ugly (lines 5, 6, and 8)
Could someone propose a better solution?
I want to perform the following task:
1. Create an array
2. Fill it up (number of elements unknown in advance)
3. Iterate through it using For Each loop (cannot do this in the in the
previous step)
I ended up with something like this:
1 Dim arr()
2 ReDim arr(0)
3 Do While <Loop Condition>
4 'Data acquisition here
5 ReDim Preserve arr(UBound(arr,1) + 1)
6 arr(UBound(arr,1) - 1) = theData
7 Loop
8 ReDim Preserve arr(UBound(arr,1) -1)
...
9 For Each item In arr
10 'First data processing here
11 Next
...
12 For Each item In arr
13 'Second data processing here
14 Next
What I don't like:
- Have to redim every time a data is added to the array (line 5)
- Must have a dummy element (line 2) to make UBound happy
- Must drop the dummy element to make my for each simpler (line 8)
- Indices are ugly (lines 5, 6, and 8)
Could someone propose a better solution?