Option Explicit Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpDest As Any, lpSource As Any, ByVal cbCopy As Long) Public Function foo() Dim xx(4) As String xx(0) = "fred" xx(1) = "dino" xx(2) = "Wilma" xx(3) = "barney" xx(4) = "Alex" Debug.Print " " Debug.Print "Before sort" Debug.Print "1 "; xx(0) Debug.Print "2 "; xx(1) Debug.Print "3 "; xx(2) Debug.Print "4 "; xx(3) Debug.Print "5 "; xx(4) Debug.Print " " SortMe xx Debug.Print "after sort" Debug.Print "1 "; xx(0) Debug.Print "2 "; xx(1) Debug.Print "3 "; xx(2) Debug.Print "4 "; xx(3) Debug.Print "5 "; xx(4) End Function Sub SortMe(varArray() As String) Dim i As Long, j As Long Dim l_Count As Long Dim l_Hold As Long ' Typical sorting routine l_Count = UBound(varArray) For i = 0 To l_Count For j = i + 1 To l_Count If varArray(i) > varArray(j) Then ' Here's the juice! SwapStrings varArray(i), varArray(j) End If Next Next End Sub Sub SwapStrings(pbString1 As String, pbString2 As String) Dim l_Hold As Long CopyMemory l_Hold, ByVal VarPtr(pbString1), 4 CopyMemory ByVal VarPtr(pbString1), ByVal VarPtr(pbString2), 4 CopyMemory ByVal VarPtr(pbString2), l_Hold, 4 End Sub
"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams