Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.



Public Function SortRedimArray(strList() As String, ByVal lLbound As Long, ByVal lUbound As Long, ByVal boolCaseSensitive As Boolean, intColumn As Integer)
' December 3rd 2000 Chris Greaves Implemented a Column key (hence qCsort)
' In this sort the array is assumed to have been REDIMensioned, i.e. 2nd index is row.
    Dim strTemp As String
'Procs    Dim strBuffer() As String
    Dim lngCurLow As Long
    Dim lngCurHigh As Long
    Dim lngCurMidpoint As Long
    lngCurLow = lLbound ' Start current low and high at actual low/high
    lngCurHigh = lUbound
    If lUbound <= lLbound Then Exit Function ' Error!
    lngCurMidpoint = (lLbound + lUbound) \ 2 ' Find the approx midpoint of the array
    strTemp = MyUCase(strList(intColumn, lngCurMidpoint), boolCaseSensitive) ' Pick as a starting point (we are making
    ' an assumption that the data *might* be in semi-sorted order already!
    Do While (lngCurLow <= lngCurHigh)
        Do While MyUCase(strList(intColumn, lngCurLow), boolCaseSensitive) < strTemp
            lngCurLow = lngCurLow + 1
            If lngCurLow = lUbound Then Exit Do
        Loop
        Do While strTemp < MyUCase(strList(intColumn, lngCurHigh), boolCaseSensitive)
            lngCurHigh = lngCurHigh - 1
            If lngCurHigh = lLbound Then Exit Do
        Loop
        If (lngCurLow <= lngCurHigh) Then ' if low is <= high then swap
            Call SwapREDIMRows(strList, lngCurLow, lngCurHigh)
            lngCurLow = lngCurLow + 1 ' CurLow++
            lngCurHigh = lngCurHigh - 1 ' CurLow--
        End If
    Loop
    If lLbound < lngCurHigh Then ' Recurse if necessary
        SortRedimArray strList(), lLbound, lngCurHigh, boolCaseSensitive, intColumn
    End If
    If lngCurLow < lUbound Then ' Recurse if necessary
        SortRedimArray strList(), lngCurLow, lUbound, boolCaseSensitive, intColumn
    End If
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1

Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.

Public Function SortRedimArray(strList() As String, ByVal lLbound As Long, ByVal lUbound As Long, ByVal boolCaseSensitive As Boolean, intColumn As Integer)
' December 3rd 2000 Chris Greaves Implemented a Column key (hence qCsort)
' In this sort the array is assumed to have been REDIMensioned, i.e. 2nd index is row.
    Dim strTemp As String
'Procs    Dim strBuffer() As String
    Dim lngCurLow As Long
    Dim lngCurHigh As Long
    Dim lngCurMidpoint As Long
    lngCurLow = lLbound ' Start current low and high at actual low/high
    lngCurHigh = lUbound
    If lUbound <= lLbound Then Exit Function ' Error!
    lngCurMidpoint = (lLbound + lUbound) \ 2 ' Find the approx midpoint of the array
    strTemp = MyUCase(strList(intColumn, lngCurMidpoint), boolCaseSensitive) ' Pick as a starting point (we are making
    ' an assumption that the data *might* be in semi-sorted order already!
    Do While (lngCurLow <= lngCurHigh)
        Do While MyUCase(strList(intColumn, lngCurLow), boolCaseSensitive) < strTemp
            lngCurLow = lngCurLow + 1
            If lngCurLow = lUbound Then Exit Do
        Loop
        Do While strTemp < MyUCase(strList(intColumn, lngCurHigh), boolCaseSensitive)
            lngCurHigh = lngCurHigh - 1
            If lngCurHigh = lLbound Then Exit Do
        Loop
        If (lngCurLow <= lngCurHigh) Then ' if low is <= high then swap
            Call SwapREDIMRows(strList, lngCurLow, lngCurHigh)
            lngCurLow = lngCurLow + 1 ' CurLow++
            lngCurHigh = lngCurHigh - 1 ' CurLow--
        End If
    Loop
    If lLbound < lngCurHigh Then ' Recurse if necessary
        SortRedimArray strList(), lLbound, lngCurHigh, boolCaseSensitive, intColumn
    End If
    If lngCurLow < lUbound Then ' Recurse if necessary
        SortRedimArray strList(), lngCurLow, lUbound, boolCaseSensitive, intColumn
    End If
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1