문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

모든 SharePoint 서버의 호스트 파일 ("C:\Windows\System32\drivers\etc\hosts")에 다음 행을 추가합니다.

127.0.0.1 SPLOAD
.

로드 밸런서를 통과하는 대신 Spload를 참조 할 때 항상 서버로 사용하도록 설정하고 다른 서버 중 하나와 이야기를 시작할 수 있습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top