Hi,
I want to do something very easy, but I can't find a build in function
and i'm stuck with writing my own.
I'm trying to get a 1D array of column x out of a 2D array...
and that works for any type in the array.
example
Dim arr(0, 1) As Array ' Store Id + some sentence
Dim retArr(1) as array ' Get Ids only
arr(0,0) = 1
arr(0,1) = "rw1"
arr(1,0) = 2
arr(1,1) = "rw2"
retArr=getColumnFromArray(arr,1)
Code:
Private Function getColumnFromArray(ByVal arr(,) As object, ByVal column As Byte) As Array
Dim arrReturn() As VariantType
Dim myType As Type = arr(0, 0).GetType()
Dim i As Integer
Dim len As Integer = UBound(arr, 0)
ReDim arrReturn(len)
For i = 0 To len
arrReturn(i) = CType(arr(i, 0), myType)
Next
Return arrReturn
End Function
and I get an error on the line
arrReturn(i) = CType(arr(i, 0), myType)
myType is not defined.
and why do I need an array of the Ids because:
The function that i'm writing loops through a filtered dataview
and get's all the ids. BUT I also want to store how many duplicate ids have been found!
So I ended up using a 2D array BUT I used the function 1Darray.BinarySearch to search for duplicate ids and that function only works for 1D arrays...
The problems came after I was reformatting my code so I could have the IdCount returned as well.