Lotus Notes / Domino Sonstiges > Tools & Downloads

Sortiertool für NotesDocumentCollection

(1/2) > >>

rar:
Hallo Leute!
Nachdem meine Suche hier erfolglos war und ich auf Notes.net fündig geworden bin, wollte ich euch dieses feine Tool zum sortieren einer Collection nicht vorenthalten.
(Falls jemand mal hier dasselbe sucht)

lg
-rar

-----------------------------------------------------------------------

http://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/601d977ec574069b85256ae100266909?OpenDocument

A Notes Document Collection is not sorted and the class does not include a method for this. When you need this functionality just add the following to you script:

(Options)
Use "MyScriptTools"

Sub Initialize
Dim array As Variant
array = SortDocumentCollection( dcol, "fieldName" )

"MyScriptTools" refers to a Script Library. Here you just copy the code I give you at the end. The "array" will contain all the documents included in your Document Collection (dcol) but shorted by the content of their field "fieldName". Where ever you are in the database by adding the three lines the relevant document collection can be sorted by the field you specify.

Let me show you an agent ("Show selected Sdocuments in alphabetic order") illustrating this:

(Options)
Option Public
Option Declare

Use "MyScriptTools"

Sub Initialize
Dim uiws As New NotesUIWorkspace
Dim uiview As NotesUIView
Dim message As String
Dim dcol As NotesDocumentCollection
Dim array As Variant

Set uiview = uiws.CurrentView
Set dcol = uiview.Documents

If dcol.count <> 0 Then

array = SortDocumentCollection( dcol, "f_VENname" )

message = "Selected documents sorted in alphabetic order" & Chr(13)_
& "by their value in the field 'f_VENname': " & Chr(13) & Chr(13)

Forall doc In array
message = message & " " & doc.f_VENname(0) & Chr(13)
End Forall
Msgbox message

Else
Msgbox "No document has been selected."
End If

End Sub



Below is the script you place in the script library "MyScriptTools"


Function DocCollectionToArray( dcol As NotesDocumentCollection ) As Variant
'Puts all documents in a collection into an array
'Used in SortDocumentCollection
'STM 2001-10-05

Dim array As Variant
Dim doc as NotesDocument
Dim i as Integer
Dim k As Long
k = dcol.Count
If k<>0 Then
Redim array( 1 To k) As NotesDocument
Set doc = dcol.GetFirstDocument
For i=1 To k
Set array(i) = doc
Set doc = dcol.GetNextDocument(doc)
Next
DocCollectionToArray = array

End If

End Function
'-------------------------------------------------------------

Function SwapInArray( array As Variant, i As Integer, j As Integer ) As Variant
'Swaps two elements in an array
'Used in SortDocumentCollection / QuickSort
'STM 2001-10-05

Dim temp As Variant

Set temp = array( i )
Set array( i ) = array( j )
Set array( j ) = temp

SwapInArray = array

End Function
'-------------------------------------------------------------

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
'-------------------------------------------------------------

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

Rob Green:
man sollte wohl erwähnen, dass das Teil - soweit ich es kurz überblickt und geschnackelt habe - (leider leider) keine Zahlen Datentypen bzw. auch Zeittypen sortieren kann, wenn es sich bei dem Sortierfeld als Bezug um einen solchen Typ handelt.

rar:
Das war mir in meinem Fall wurscht, da ich nur nach einem String sortieren wollte und das hat in meinem Fall wunderbar funktioniert... ;D

Axel:

--- Zitat von: Rob Green am 07.05.03 - 10:49:32 ---man sollte wohl erwähnen, dass das Teil - soweit ich es kurz überblickt und geschnackelt habe - (leider leider) keine Zahlen Datentypen bzw. auch Zeittypen sortieren kann, wenn es sich bei dem Sortierfeld als Bezug um einen solchen Typ handelt.

--- Ende Zitat ---

Hi Rob,

du hast recht. Leider!  ;) :-\

Ich kenne dieses Sortiertool und hab's auch schon eingesetzt und funktioniert auch ganz gut. Leider geht das nur für Text.


Axel


PS:

Wäre es unverschämt dich zu bitten, es kurz umzuschreiben, dass man auch Zahlen- und Zeittypen sortieren kann ?    ;) ;D ;D ;D

Rob Green:
warum nicht..ich bin mir sogar recht sicher, daß es Sortierroutinen für Zahlenwerte bereits bestimmt irgendwo gibt (sei es Martin Scott oder in dieser unter Downloads von mir geposteten Datei eines Autors mit zig Sortierfunktionen). Könnte man dann übernehmen.

Aber die Frage auf die hinauswollte: is es richtig, daß Feldwerte vom Typ Datum/Zeit als Double einwandfrei sortierbar sind oder muß ich da noch was berücksichtigen? UND, gibt es empfohlene Sortierroutinen eigens für Zahlenwerte?

Navigation

[0] Themen-Index

[#] Nächste Seite

Zur normalen Ansicht wechseln