Domino Code Fragment

Code Name*
Sort - Bubble Sort for a Document Collection
Date*
04/29/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.15.193.45
Description*
Sorts a Document Collection
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
"Here is an example that does a bubble sort on the document collection using two fields
as the sort key:"

Sub Swap(doc1 As NotesDocument ,doc2 As NotesDocument)
Dim d As NotesDocument
Set d = doc1
Set doc1 = doc2
Set doc2 = d
End Sub


Sub CollectionToSortedArray(col As NotesDocumentCollection, docs() As NotesDocument)
Dim i As Integer
Dim doc As NotesDocument
Dim n As Integer, sorted As Integer
Dim s1, s2 As String


n = col.count
Redim docs(n) As NotesDocument
' push to array
For i = 0 To n - 1
Set docs(i) = col.GetNthDocument(i+1)
Next


'bubble sort array
sorted = False
Do While (sorted = False)
sorted = True
For i = 0 To n - 2
' sort based on QuoteNo and ItemNo fields
s1 = docs(i).QuoteNo(0) & docs(i).ItemNo(0)
s2 = docs(i+1).QuoteNo(0) & docs(i+1).ItemNo(0)
If(Strcomp(s1, s2, 5) = 1) Then 'No Pitch, No Case Compare
Call Swap(docs(i),docs(i+1))
sorted = False
End If
Next
Loop
End Sub