Felix
Felix

Reputation: 821

How do you strip useful values out of a multi-dimensional VBA array?

Function returns a 4-dimensional array in the form (j,0)(i,0). Want to convert this into a 2-dimensional array in the form (j,i). How do I move the values i to the slot bound next to j and then re-dimension the array to remove the "spare" two dimensions?

Upvotes: 1

Views: 668

Answers (1)

Splitting your question into two parts:

1. How do I move the values i to the slot bound next to j

Create a new two-dimensional array. Loop through both arrays and assign values from the old four-dimensional array to the new two-dimensional array as appropriate. Then Erase the old four-dimensional array to free up memory.

2. and then re-dimension the array to remove the "spare" two dimensions?

This is not possible -- or at least not without erasing the array contents. You could remove the flat dimensions using ReDim, but erases all the data contained in the array, thus defeating your purpose.

That's why I made you make a new array in part 1 above.

Upvotes: 5

Related Questions