>Option Explicit >Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpDest As Any, lpSource As Any, ByVal cbCopy As Long) > >Public Function foo2() > > Dim xx(50000) As String > > Debug.Print "Generating Data" > PopulateArray xx > > Debug.Print "Starting to sort", Now > > BubbleSort xx > > Debug.Print "Finish:", Now > >End Function > >Sub BubbleSort(varArray() As String) > Dim i As Long > Dim l_Count As Long > Dim l_Swap As Boolean > > l_Count = UBound(varArray) > > l_Swap = True > Do While l_Swap > For i = 0 To l_Count - 1 > l_Swap = False > If varArray(i) > varArray(i + 1) Then > l_Swap = True > SwapStrings varArray(i), varArray(i + 1) > End If > Next > Loop >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 > > >Sub PopulateArray(varArray() As String) > Dim i As Long, j As Long > Dim l_Count As Long, lcStr As String > > ' Typical sorting routine > l_Count = UBound(varArray) > Randomize > lcStr = "" > For i = 0 To l_Count > lcStr = "" > For j = 1 To 50 > lcStr = lcStr + Chr$((Rnd(1) * 26) + 65) > Next > varArray(i) = lcStr > Next >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