hi all,
just want an opinion from all of you out there on how to do descending sort. I got this sort example code from the net but it does ascending sort. Is the a possibility that if I change a few line inside the code it will come out as descending sort? I have a text file which the output will be like this:
and i want to sort it descending based on the first word before the (:) sign.

Public Sub SortTextFile(pstrFile As String)
   Dim strLine() As String
   strLine = Split(LoadFileToString(pstrFile), vbNewLine)
   QuickSort1 strLine
   SaveStringToFile Join(strLine, vbNewLine), pstrFile
End Sub
Public Function LoadFileToString(pstrFile As String) As String
   Dim bytArray() As Byte
   Dim strReturn As String
   Dim FileNumber As Long
   FileNumber = FreeFile
   Open pstrFile For Binary Access Read As #FileNumber
   ReDim bytArray(LOF(FileNumber) - 1)
   Get #FileNumber, 1, bytArray
   Close #FileNumber
   strReturn = StrConv(bytArray, vbUnicode)
   Erase bytArray
   Do While InStr(strReturn, vbNewLine & vbNewLine)
       strReturn = Replace(strReturn, vbNewLine & vbNewLine, vbNewLine)
   Do While Right(strReturn, 2) = vbNewLine
       strReturn = Left(strReturn, Len(strReturn) - 2)
   LoadFileToString = strReturn
End Function
Public Sub SaveStringToFile(pstrText As String, pstrFile As String)
   Dim FileNumber As Long
   If Len(Dir(pstrFile)) Then Kill pstrFile
   FileNumber = FreeFile()
   Open pstrFile For Output As #FileNumber
   Print #FileNumber, pstrText
End Sub
' Omit plngLeft & plngRight; they are used internally during recursion
Public Sub QuickSort1(ByRef pvarArray As Variant, Optional ByVal plngLeft As Long, Optional ByVal plngRight As Long)
   Dim lngFirst As Long
   Dim lngLast As Long
   Dim varMid As Variant
   Dim varSwap As Variant
   If plngRight = 0 Then
       plngLeft = LBound(pvarArray)
       plngRight = UBound(pvarArray)
   End If
   lngFirst = plngLeft
   lngLast = plngRight
   varMid = pvarArray((plngLeft + plngRight) \ 2)
       Do While pvarArray(lngFirst) < varMid And lngFirst < plngRight
           lngFirst = lngFirst + 1
       Do While varMid < pvarArray(lngLast) And lngLast > plngLeft
           lngLast = lngLast - 1
       If lngFirst <= lngLast Then
           varSwap = pvarArray(lngFirst)
           pvarArray(lngFirst) = pvarArray(lngLast)
           pvarArray(lngLast) = varSwap
           lngFirst = lngFirst + 1
           lngLast = lngLast - 1
       End If
   Loop Until lngFirst > lngLast
   If plngLeft < lngLast Then QuickSort1 pvarArray, plngLeft, lngLast
   If lngFirst < plngRight Then QuickSort1 pvarArray, lngFirst, plngRight
End Sub
This article has been dead for over six months. Start a new discussion instead.