I'm currently translating a VBA project into VB.NET. And I have a little issue with the sorting of a datatable.
My table look like :
... | ... | Firstname3 | Name3 | Pay3 | Firstname1 | Name1 | Pay1 | Firstname2 | Name2 | Pay2 |...
... | ... | Firstname2 | Name2 | Pay2 | Firstname3 | Name3 | Pay3 | Firstname1 | Name1 | Pay1 |...
And so on... I export the 56 columns needed from the datatable into an array and try to sort it horizontaly on the Name. I did it that way in VBA :
Public Sub SortTable(ByRef aggTab(,) As Object, ByVal columnToSortOn As Integer, ByVal lowerValue As Byte,
ByVal upperValue As Byte)
Dim ref As Object = aggTab((lowerValue + upperValue) \ 2, columnToSortOn)
Dim refLowerValue As Byte = lowerValue
Dim refUpperValue As Byte = upperValue
Dim temp As Object
Do
Do While aggTab(refLowerValue, columnToSortOn) < ref
refLowerValue = refLowerValue + 1
Loop
Do While ref < aggTab(refUpperValue, columnToSortOn)
refUpperValue = refUpperValue - 1
Loop
If refLowerValue <= refUpperValue Then
For i = LBound(aggTab, 2) To UBound(aggTab, 2)
temp = aggTab(refLowerValue, i)
aggTab(refLowerValue, i) = aggTab(refUpperValue, i)
aggTab(refUpperValue, i) = temp
Next i
refLowerValue = refLowerValue + 1 : refUpperValue = refUpperValue - 1
End If
Loop While refLowerValue <= refUpperValue
If refLowerValue < upperValue Then Call SortTable(aggTab, columnToSortOn, refLowerValue, upperValue)
If lowerValue < refUpperValue Then Call SortTable(aggTab, columnToSortOn, lowerValue, refUpperValue)
End Sub
But when I convert the code into VB.NET it doesn't work properly. Does anyone can explain me why? Because in excel it work perfectly.