views:

299

answers:

1

I have an application in VBA that gives to my VB.Net dll one bi-dimensional variant. It is a an array, in which every component is a another array containing two positions.

I want to get this two-position array. When I am using VBA I can access directly the data from each position by doing:

dataArray(index, 0) or dataArray(index, 1)

And when I want to get the two-position array I can use:

Dim posArray as variant
posArray = dataArray(index)

posArray(0) contains dataArray(index, 0) and posArray(1) contains dataArray(index, 1).

But when I am using VB.Net, I can access directly the data, just like the first example. However, when I try to get one dimension from the two-dimension array, like I did in the second example, it is not possible.

Dim posArray as Object
posArray = dataArray(index)

It says "Attempted to operate on an array with the incorrect number of dimensions."

I have tried everything to make it work, and I don't want to make the attribution one by one, like:

posArray(0) = dataArray(index, 0)
posArray(1) = dataArray(index, 1)

Thank you for the help.

+1  A: 

You'll need to spin through and generate the 1D array yourself. There's no library call in .NET to do it for you.

dim arraySlice as string[yourArrayWidth]
for index = 0 to yourArrayWidth
  arraySlice[index] = yourArray[4, index]
next

The example above would grab row 4 out of yourArray and stick it into arraySlice for you. Naturally, you'll want to clean that up and put it into a function that accepts a rowIndex as a parameter (and another function for splitting vertically that accepts a columnIndex).

It's little functions like this that you'll collect over the years into your own utility library. 5 years from now, you'll need an ArraySlice and you'll already have a function to do it.

Jason Kester