Page 1 sur 1
Tri d'un tableau par la méthode "Selection"

Publié:
22 Fév 2008 à 11:52
par Michael DELIQUE
- Code : Tout sélectionner
Public Sub SortSelection(vrTable As Variant)
'Tri par selection par ordre croissant
'Déclaration Variables
Dim nbUBound As Long
Dim nbLbound As Long
Dim nbPivot As Long
Dim i As Long
Dim J As Long
Dim vrValue As Variant
On Error Goto ErreurHandle
nbLbound = Lbound(vrTable)
nbUBound = Ubound(vrTable)
If nbUBound = nbLbound Then
'si 1 seule donnée pas de traitement
Exit Sub
Elseif nbUBound = (nbLbound+1) Then
'si uniquement 2 données
If vrTable(nbLbound) > vrTable(nbUBound) Then
vrValue = vrTable(nbUBound)
vrTable(nbUBound) = vrTable(nbLbound)
vrTable(nbLbound) = vrValue
vrValue = Null
End If
Exit Sub
End If
For i=nbLbound To (nbUBound-1)
nbPivot = i
For J=(i+1) To nbUBound
If vrTable(J) < vrTable(nbPivot) Then
nbPivot = J
End If
Next
If i <> nbPivot Then
vrValue = vrTable(i)
vrTable(i) = vrTable(nbPivot)
vrTable(nbPivot) = vrValue
vrValue = Null
End If
Next
Exit Sub
ErreurHandle:
Msgbox "("+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
Exit Sub
End Sub