logo

New Response

« Return to the blog entry

You are replying to:

    • avatar
    • Nick Wall
    • Posted on Wed 1 Feb 2006 03:29 AM

    You already have your solution, but with regard to "sorting" a NotesDocumentCollection after a db.search()...I have used the following, it could

    be adapted for dates, numbers, etc.

    (I think I got this from LD6 forum, so thanks to whoever originally wrote it):

    Public Function SortDocumentCollection( dcol As NotesDocumentCollection, fieldName As String) As Variant

    'Sort documents in a collection in alphabetic order by the field specified

    'STM 2001-10-05

    Dim session As New NotesSession

    Dim db As NotesDatabase

    Set db = session.CurrentDatabase

    Dim array As Variant

    Dim k As Integer

    k = dcol.count

    If k <> 0 Then

    Redim array( 1 To k )

    array = docCollectionToArray( dcol )

    ' // Need to add a value at the end that will always be greater than all - language dependent

    Redim Preserve array( 1 To k+1 )

    Set array( k+1) = db.CreateDocument

    Call array( k+1).ReplaceItemValue( fieldName, "ÅÅÅÅÅÅÅ" )

    array = QuickSort( array, fieldName, Lbound(array), Ubound(array) - 1 )

    Redim Preserve array( 1 To k )

    SortDocumentCollection = array

    Else

    SortDocumentCollection = ""

    End If

    End Function

    Private Function QuickSort (array As Variant, fieldName As String, leftpos As Integer, rightpos As Integer) As Variant

    'Sub function in SortDocumentCollection

    'STM 2001-10-05

    Dim i As Integer

    Dim j As Integer

    Dim pivot As String

    If ( leftpos < rightpos ) Then

    i = leftpos

    j = rightpos + 1

    pivot = Ucase( array(leftpos).GetFirstItem(fieldName).Text )

    Do

    Do

    i = i + 1

    Loop While Ucase( array(i).GetFirstItem(fieldName).Text ) < pivot And i <= rightpos

    Do

    j = j - 1

    Loop While Ucase( array(j).GetFirstItem(fieldName).Text ) > pivot And j >= leftpos

    If ( i < j ) Then

    array = SwapInArray( array, i, j )

    End If

    Loop While ( i < j )

    array = SwapInArray( array, leftpos, j )

    Call QuickSort( array, fieldName, leftpos, j - 1 )

    Call QuickSort( array, fieldName, j + 1, rightpos )

    End If

    QuickSort = array

    End Function

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: