1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
Public Function SortChaine(ByVal s As Variant) As Variant
Const csDelim As String = "-"
Dim asTab() As String
Dim bLeft As Boolean, bRight As Boolean
If Nz(Len(s)) Then
If Left(s, 1) = csDelim Then
s = Mid(s, 2)
bLeft = True
End If
If Right(s, 1) = csDelim Then
s = Mid(s, 1, Len(s) - 1)
bRight = True
End If
asTab = Split(s, csDelim)
ShellTri asTab
s = Join(asTab, csDelim)
If bLeft Then s = csDelim & s
If bRight Then s = s & csDelim
End If
SortChaine = s
End Function
Public Sub ShellTri(ByRef atab() As String)
Dim i As Long, j As Long, inc As Long, n As Long, lb As Long
Dim v As String
lb = LBound(atab)
inc = lb * 3 + 1
n = UBound(atab)
While inc < n
inc = inc * 3 + 1
Wend
Do
inc = inc / 3
For i = inc + lb To n - 1
v = atab(i)
j = i
Do While CInt(atab(j - inc)) > CInt(v)
atab(j) = atab(j - inc)
j = j - inc
If j < inc + lb Then Exit Do
Loop
atab(j) = v
Next i
Loop While inc > lb
End Sub |
Partager