Hi! May I ask for help?
I have this script below that collects document and returns field values of each document specifically the aename and date.
I used bubble sort to sort aenames and it work fine however the dates corresponding to that aename was wrong:
the output of the script before sorting was:
Name Date
A 05/25/2004
B 05/26/2004
C 05/27/2004
B 05/28/2004
A 05/29/2004
C 05/30/2004
the output of the script after sorting was:
Name Date
A 05/25/2004
A 05/26/2004
B 05/27/2004
B 05/28/2004
C 05/29/2004
C 05/30/2004
the dates does not correspond to the user. do you have other lotuscript options in
such a way that the name corresponds to the date like this below
Name Date
A 05/25/2004
A 05/29/2004
B 05/26/2004
B 05/28/2004
C 05/27/2004
C 05/30/2004
Sub Click(Source As Button)
Dim ws As New notesuiworkspace
Dim uidoc As notesuidocument
Dim doc As notesdocument
Dim vdoc As notesdocument
Dim s As NotesSession
Dim db As NotesDatabase
Dim viewkey As String
Dim v As notesview
Dim ventry As notesviewentry
Dim vecol As notesviewentrycollection
Dim dcol As notesdocumentcollection
Dim nameArray() As String
Dim dateArray() As String
Dim count As String
Dim dateTime As New NotesDateTime("01/01/2000")
Dim totals As Double
Set S = New NotesSession
Set db=s.Currentdatabase
Set uidoc = ws.currentdocument
Set doc = uidoc.document
Set v = db.getview("AE")
Set dcol = db.Search ("(Form = ""log"")", dateTime, 0)
Dim x
x = dcol.Count
Redim nameArray(dcol.count-1)
Redim dateArray(dcol.count-1)
totals = 0
count = 0
Set vdoc = dcol.getfirstdocument
Do Until vdoc Is Nothing
nameArray(count) = vdoc.ae_name(0)
If vdoc.act_type(0)="Client Call/Visitation" Then
dateArray(count) = vdoc.d_locator(0)
Else
dateArray(count) = vdoc.untitled4(0)
End If
count = count + 1
Set vdoc = dcol.getnextdocument(vdoc)
Loop
call bub_sort(nameArray)
doc.aename = nameArray
doc.date = dateArray
End Sub
Sub bub_sort(namearray As Variant)
'returns a sorted array based on a complexity of O(n^2) using a bubble sort
If Not Isarray(namearray) Then
’ Print “bub_sort: not receiving array”
Exit Sub
End If
Dim top, bot, cur, cur2 As Integer
top=Ubound (namearray)
bot=Lbound (namearray)
If top=bot Then
' Print "bub_sort: only one element"
Exit Sub
End If
Dim tmp_element As Variant
For cur=bot To top
cur2=cur
Do While cur2 > bot 'bubble up
If (namearray(cur2) > namearray(cur2-1)) Then
Exit Do
Else
'swap
tmp_element=namearray(cur2)
namearray(cur2)=namearray(cur2-1)
namearray(cur2-1)=tmp_element
End If
cur2=cur2-1
Loop
Next
End Sub