Buongiorno,
più di qualche anno fa ho scritto questo codice per esercizio.
L'ho ripreso e mi sono reso conto che non funziona qualora vengano specificati elementi multipli in ColumnIndex.
L'algoritmo prende in considerazione sempre e solo il valore all'indice zero.
Spero che qualcuno sia interessato ad aiutarmi a risolvere.
Function OrderBy(ByVal Data As String(,), ByVal ColumnsIndex As Integer(), ByVal ColumnsTypes() As String, Optional ByVal Direction As Boolean = True) As String(,)
Dim _Data(Data.GetUpperBound(0)- 1, Data.GetUpperBound(1)) As String
Dim Rows As Integer = _Data.GetUpperBound(0)
Dim Columns As Integer = _Data.GetUpperBound(1)
Dim DirectiveColumns As Integer = ColumnsIndex.GetLength(0)
For i As Integer = 0 To Rows - 1 - 1
For Row As Integer = i + 1 To Rows - 1
For Column As Integer = 0 To ColumnsIndex.Length - 1
Dim C As Integer = ColumnsIndex(Column)
Dim V0 As String = _Data(i, C)
Dim V1 As String = _Data(Row, C)
Select Case Direction
Case = False
If V0.CompareTo(V1) < 0 Then
For d As Integer = 0 To Columns - 1
Dim h As String = _Data(Row, d)
_Data(Row, d) = _Data(i, d)
_Data(i, d) = h
Next
Exit For
ElseIf Direction = False AndAlso V0.CompareTo(V1) > 0 Then
Exit For
End If
Case = True
If V0.CompareTo(V1) > 0 Then
For d As Integer = 0 To Columns - 1
Dim h As String = _Data(Row, d)
_Data(Row, d) = _Data(i, d)
_Data(i, d) = h
Next
Exit For
ElseIf Direction = True AndAlso V0.CompareTo(V1) < 0 Then
Exit For
End If
End Select
Next
Next
Next
Return _Data
End Function