StrCmpLogicalW API を使った Sort のサンプルです。
VB
1Private Declare Function StrCmpLogicalW Lib "Shlwapi.dll" (ByVal psz1 As Long, ByVal psz2 As Long) As Long
2
3Function ExplorerCompare(ByVal psz1 As String, ByVal psz2 As String, ByVal reverse As Boolean) As Long
4 Dim result As Long
5 result = StrCmpLogicalW(StrPtr(psz1), StrPtr(psz2))
6 If reverse Then
7 ExplorerCompare = 0 - result
8 Else
9 ExplorerCompare = result
10 End If
11End Function
12
13Sub ExplorerSort(ByRef sortArray() As String, ByVal reverse As Boolean)
14 Dim i As Long
15 Dim j As Long
16 Dim k As Long
17 Dim lngLow As Long
18 Dim lngHigh As Long
19 Dim tmp As String
20
21 lngLow = LBound(sortArray)
22 lngHigh = UBound(sortArray)
23
24 For i = lngHigh To lngLow Step -1
25 For j = lngLow + 1 To i
26 k = j - 1
27 If ExplorerCompare(sortArray(k), sortArray(j), reverse) > 0 Then
28 tmp = sortArray(j)
29 sortArray(j) = sortArray(k)
30 sortArray(k) = tmp
31 End If
32 Next j
33 Next i
34End Sub
使い方
VB
1Const MaxCount As Long = 100
2
3Dim sortArray(MaxCount - 1) As String
4Dim i As Integer
5Dim v As Variant
6
7For i = 0 To MaxCount - 1
8 sortArray(i) = StrConv(CStr(i), vbWide)
9Next
10
11Debug.Print "---- 逆順 ----"
12ExplorerSort sortArray, True
13For Each v In sortArray
14 Debug.Print v
15Next
16
17Debug.Print "---- 昇順 ----"
18ExplorerSort sortArray, False
19
20For Each v In sortArray
21 Debug.Print v
22Next
23
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。