Sort an array of collections.....
Posted
#1
(In Topic #557)
Regular

Code
Dim tmp_col As Collection[] = New Collection[]
tmp_col.Add([
"name": "toto4",
"test": "quattre"
])
tmp_col.Add([
"name": "toto6",
"test": "six"
])
tmp_col.Add([
"name": "toto1",
"test": "un"
])
tmp_col.Add([
"name": "toto3",
"test": "trois"
])
Write the function like this :
Code
Public Function ColSort(col As Collection[], ColKey As String, trie As Integer) As Collection[]
Dim tmp_col As Collection[] = New Collection[col.count]
Dim tmp_ar As String[] = New String[]
For i As Integer = 0 To col.count - 1
tmp_ar.Add(col[i][Colkey] & " (" & i & ")")
Next
tmp_ar.Sort(trie)
For i = 0 To tmp_ar.count - 1
tmp_col[i] = col[CInt(Split(tmp_ar[i], " ()", "", True)[1])]
Next
Return tmp_col
End
And we call the function like this :
Code
tmp_col = ColSort(tmp_col, "name", gb.Ascent)
Et voila, Enumerate collections in the array and they are sorted by name!
Olivier
Posted
Regular

Olivier
1 guest and 0 members have just viewed this.



