Das Notes Forum
Domino 9 und frühere Versionen => Entwicklung => Thema gestartet von: Don Pasquale am 15.08.03 - 09:56:06
-
Gibt es irgendwas, dass gegen folgenden Code spricht,
bzw. an welcher Stelle könnte ich den noch optimieren ?
Const VIEW_AKTUELL = "($ALL)"
Dim ws As New NotesUiWorkspace
Dim view As NotesView
Dim session As New NotesSession
Dim Doc As NotesDocument
Dim DocDelete As NotesDocument
Dim LOESCHLISTE List As String
Set db = session.CurrentDatabase
Set view = db.GetView(VIEW_AKTUELL)
Set doc = view.GetFirstDocument
While Not doc Is Nothing
If doc.Kriterium(0) = "JA" Then
j = j + 1
LOESCHLISTE(j) = Doc.UniversalID
End If
Set doc = view.GetNextDocument(doc)
Wend
Set doc = Nothing
Forall x In LOESCHLISTE
Set DocDelete = db.GetDocumentByUNID(X)
Call DocDelete.Remove( True )
Set DocDelete = Nothing
End Forall
Set view = db.GetView(VIEW_AKTUELL)
Call ws.viewrefresh()
Ciao
Don Pasquale
-
Das spricht dagegen:
listName( listTag ) = value
where listName is the name of the list, listTag is a string that uniquely identifies the element, and value is the value you want to assign to the element.
Dein j muss ein String sein, also
dim jtag as string
...
jtag = cstr(j)
LOESCHLISTE(jtag) = Doc.UniversalID
Andreas
-
Warum löschst du die Dokumente nicht direkt?
Du kannst doch wenn du eins gefunden hast, was gelöscht werden soll dirkt sagen "Call Doc.Remove( True )"
-
@Glombi
Die Loeschliste ist eine LISTE des Typs Strings,
das "j" sollte vom Typ Integer sein.
@Gruenkohl
Das ist genau der Punkt auf den ich selbst hereingefallen bin.
Wenn Du eine Collection hast, mit 10 Dokumenten
und dass 5.te Dokument wird gelöscht, dann wird dass 6te Dokument zum 5ten Dokument und bei der nächsten Iteration
wird genau dieses neue 5.te Dokument ausgelassen.
Wenn Du beispielsweise die gesamte Collection mit n-Elementen löschen möchtest, gelingt Dir das erst in Wurzel N durchläufen.
Verbesserungen
Dim LOESCHLISTE List As String*32 ( oder wie lange ist die UniversalID ?)
Dim j As Integer
Dim db As NotesDatabase
Die Dimensionierungen sollten wegen Speicherfragmentierung in der Reihenfolge der Größe der Objekte stehen.
Ciao
Don Pasquale
-
Ja, aber nur wenn du sagst: doc = view.getnextdocument(doc).
Wenn du aber fragst und nur das nächste Doc nimmst, wenn du das aktuelle Doc nicht gelöscht hast müsste es gehen, oder?
-
@Gruenkohl
;D
Jetzt baust Du aber ein Fahrrad.
Ich halte das für die sauberere Lösung. Der Haken wäre nur ein Overflow in der LIST.
Ciao
Don Pasquale
-
Hi,
wir wär's den mit diesem Ansatz ?
...
Set doc = collection.GetFirstDocument
While Not (doc Is Nothing)
Set tmpdoc = collection.GetNextDocument(doc)
If doc.Kriterium(0) = "JA" Then
Call collection.DeleteDocument(doc)
End If
Set doc = tmpdoc
Wend 'While Not (doc Is Nothing)
Call collection.RemoveAll( True )
...
Axel
-
Die Lösung von Axel ist die eleganteste Weil sie alle Löschoperationen am Ende durchführt. Aber es geht auch so:
Const VIEW_AKTUELL = "($ALL)"
Dim ws As New NotesUiWorkspace
Dim view As NotesView
Dim session As New NotesSession
Dim Doc As NotesDocument
Dim Olddoc as notesdocument
Set db = session.CurrentDatabase
Set view = db.GetView(VIEW_AKTUELL)
Set doc = view.GetFirstDocument
While Not doc Is Nothing
set olddoc = doc
If doc.Kriterium(0) = "JA" Then
call doc.remove(true)
Set doc = view.GetNextDocument(Olddoc)
End If
Wend
Set doc = Nothing
Set view = db.GetView(VIEW_AKTUELL)
Call ws.viewrefresh()
N.B. Diese Art der Verarbeitung gilt übrigens auch, wenn du z.B. durch eine View marschierst und in einzelnen Dokumenten abhängig von deinem Status etwas änderst. In dem Moment wo du einen Doc.Save brauchst musst du mit diesem Schema arbeiten.
Thomas
-
@Don Pasquale:
Laut Hilfe muss ListTag ein String sein - ich habe das nur zitiert. Du verwendest ein Integer. Das sollte also nicht gehen. Falls doch, stimmt die Hilfe nicht ganz (wie so oft).
Andreas