mscorlib.dll is a .Net framework assembly, remember that Office and Access are based on COM (and have no idea of what .net is).
I use a class module-
'--- CLASS MODULE TO SORT ANY ARRAY ---
Dim V1() As String, LB As Long, UB As Long, i As Integer
'return pointer to array, i.e. Variant = Object.GetArray
Public Property Get GetArray() As Variant
GetArray = V1()
End Property
'get the array, i.e. Object.GetArray = Array()
Public Property Let GetArray(V As Variant)
LB = LBound(V): UB = UBound(V) 'lower/upper bounds
ReDim V1(LB To UB) As String
For i = LB To UB: V1(i) = CStr(V(i)): Next 'convert to string array
End Property
'method to sort the array, i.e. Object.Sort
Public Sub Sort()
LB = LBound(V1): UB = UBound(V1)
QuickSort V1(), LB, UB
End Sub
'Call QuickSort(MyArray, LBound(MyArray), UBound(MyArray))
Private Sub QuickSort(ByRef arArray() As String, ByVal LB As Long, ByVal UB As Long)
Dim P1 As Long, P2 As Long, Ref As String, TEMP As String
P1 = LB
P2 = UB
Ref = arArray((P1 + P2) / 2)
Do
Do While (arArray(P1) < Ref): P1 = P1 + 1: Loop
Do While (arArray(P2) > Ref): P2 = P2 - 1: Loop
If P1 <= P2 Then
TEMP = arArray(P1)
arArray(P1) = arArray(P2)
arArray(P2) = TEMP
P1 = P1 + 1
P2 = P2 - 1
End If
Loop Until (P1 > P2)
If LB < P2 Then Call QuickSort(arArray, LB, P2)
If P1 < UB Then Call QuickSort(arArray, P1, UB)
End Sub
'--- end class module ---
Sub Sample()
'INIT ARRAYS
'---------------------------------------
Dim A() As String 'string array, dynamic
Dim N(0 To 4) As Integer 'integer array, fixed
Dim V As Variant 'pointer to sorted array
Dim i As Integer
A = Split("F,C,A,E,D,B", ",") 'string array, unsorted
For i = 0 To 4: N(i) = 5 - i: Next 'integer array, unsorted
'show unsorted array elements
For i = LBound(A) To UBound(A): Debug.Print A(i);: Next: Debug.Print
For i = LBound(N) To UBound(N): Debug.Print N(i);: Next: Debug.Print
'---------------------------------------
'CLASS OBJECT TO SORT ARRAY
'---------------------------------------
Dim myArray As New clsArray 'new instance class object
'string sample
myArray.GetArray = A 'assign array to object
myArray.Sort 'sort method
V = myArray.GetArray 'return a variant (pointer to sorted array)
For i = LBound(A) To UBound(A): A(i) = V(i): Next 'copy sorted back to original array
For i = LBound(A) To UBound(A): Debug.Print A(i);: Next: Debug.Print
'integer sample
myArray.GetArray = N
myArray.Sort
V = myArray.GetArray
For i = LBound(N) To UBound(N): N(i) = V(i): Next 'copy sorted back to original array
For i = LBound(N) To UBound(N): Debug.Print N(i);: Next: Debug.Print
Set myArray = Nothing 'dispose object, free memory
'---------------------------------------
End Sub