This function will sort alphanumerically:
Private Sub SortAlphaNum(List() As String)
Dim TagedList() As String
ReDim taggedlist(UBound(List))
Dim item As String
Dim ch As String
Dim num As String
Dim digitCount As Integer
Dim i, j As Integer
For i = 0 To UBound(List) - 1
item = ""
inNum = False
num = ""
digitCount = 0
j = 1
While j <= Len(List(i))
ch = Mid(List(i), j, 1)
If ch < "0" Or ch > "9" Then
item = item & ch
Else
While ch >= "0" And ch <= "9"
digitCount = digitCount + 1
num = num & ch
j = j + 1
ch = Mid(List(i), j, 1)
Wend
item = item & digitCount
item = item & num
If j <= Len(List(i)) Then
item = item & ch
End If
End If
j = j + 1
Wend
taggedlist(i) = item
Next i
For i = 0 To UBound(taggedlist) - 2
For j = 0 To UBound(taggedlist) - 2
If taggedlist(j) > taggedlist(j + 1) Then
item = taggedlist(j)
taggedlist(j) = taggedlist(j + 1)
taggedlist(j + 1) = item
item = List(j)
List(j) = List(j + 1)
List(j + 1) = item
End If
Next j
Next i
End Sub
To call it use something like this:
Private Sub Command1_Click()
Dim i As Integer
Dim mylist() As String
ReDim mylist(List1.ListCount)
For i = 0 To List1.ListCount - 1
mylist(i) = List1.List(i)
Next i
Call SortAlphaNum(mylist)
List2.Clear
For i = 0 To List1.ListCount
Call List2.AddItem(mylist(i))
Next i
End Sub
This sorts by putting a "tag" in front of digit groups. For example: the two files
CR 9.1.09.pdf
CR 13.08.08.pdf
will be tagged as
CR
19.
11.
209.pdf
CR
213.
208.
208.pdf
This can now be sorted normally and then redisplayed using the original list.
I have made the assumption (probably bad) that all arrays start at 0.