Ich hab da einen Agent:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim dc As NotesDocumentCollection
Dim size As Long
Dim count As Long
Set db = session.CurrentDatabase
Set dc = db.Search( {Form="Appointment"}, Nothing, 0)
size = 0
count = 0
If( dc Is Nothing Or dc.Count = 0) Then
Messagebox "Keine Collection!"
Exit Sub
End If
Set doc = dc.GetFirstDocument
While( Not doc Is Nothing )
count = count + 1
size = size + doc.Size
Set doc = dc.GetNextDocument(doc)
Wend
Dim average As Double
average = size / count
Messagebox Cstr(count) & " Dokumente haben " & Cstr(size) & " bytes. Durchschnitt: " & Cstr(Average)
Exit Sub
ERRORHANDLING:
Print "Fehler"
Soda, damit die i-Tüpferl-Reitere aufhört:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim dc As NotesDocumentCollection
Dim size As Long
Dim count As Long
On Error Goto ERRORHANDLING_SPEZIELL_FUER_koehlerbv
Set db = session.CurrentDatabase
Set dc = db.Search( {Form="Appointment" | Form ="Notice"}, Nothing, 0)
size = 0
count = 0
If( dc Is Nothing Or dc.Count = 0) Then
Messagebox "Keine Collection!"
Exit Sub
End If
Set doc = dc.GetFirstDocument
While( Not doc Is Nothing )
count = count + 1
size = size + doc.Size
Set doc = dc.GetNextDocument(doc)
Wend
Dim average As Double
average = size / count
Messagebox Cstr(count) & " Dokumente haben " & Cstr(size) & " bytes. Durchschnitt: " & Cstr(Average)
Exit Sub
ERRORHANDLING_SPEZIELL_FUER_koehlerbv:
Messagebox( "Ein Fehler ist im Agenten 'Size Of Appointments' aufgetreten.Details: " & Error() & ", " & Err() & ", " &Erl() )
In meiner Mail-DB:
Ohne Notices: 4.143 Dokumente mit 59,7 MB
Mit Notices: 4.228 Dokumente mit 60,4 MB
Tode, danke für den Hinweis, das war mir neu. Man sollte sich die Zeit nehmen, auch von "bekannten" Objekte ab und an die Doku lesen, dann findet man so was:
A deletion stub is returned for a document deleted after creation of the collection or for a document to which you do not have read access. Use IsValid in NotesDocument to check whether a document is real (True) or a deletion stub (False).
Daher folgender Code:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim dc As NotesDocumentCollection
Dim size As Long
Dim count As Long
On Error Goto ERRORHANDLING_SPEZIELL_FUER_koehlerbv
Set db = session.CurrentDatabase
Set dc = db.Search( {Form="Appointment" | Form ="Notice"}, Nothing, 0)
size = 0
count = 0
If( dc Is Nothing Or dc.Count = 0) Then
Messagebox "Keine Collection!"
Exit Sub
End If
Set doc = dc.GetFirstDocument
While( Not doc Is Nothing )
'A deletion stub is returned for a document deleted after creation of the collection or for a document to which you do not have read access.
' Therefore: Check, if document is valid, otherwise it's a deletion stub.
If doc.IsValid = True Then '
count = count + 1
size = size + doc.Size
End If
Set doc = dc.GetNextDocument(doc)
Wend
Dim average As Double
average = size / count
Messagebox Cstr(count) & " Dokumente haben " & Cstr(size) & " bytes. Durchschnitt: " & Cstr(Average)
Exit Sub
ERRORHANDLING_SPEZIELL_FUER_koehlerbv:
Messagebox( "Ein Fehler ist im Agenten 'Size Of Appointments' aufgetreten.Details: " & Error() & ", " & Err() & ", " &Erl() )
Das ist jetzt in keinster Weise kleinlich gemeint, ich bin vielmehr selber schon darüber gestolpert, dass selbst Isvalid nicht ausreichte. Daher folgender Vorschlag für einen Code, der bei mir seit 2003 in hunderten DBs nie einen Fehler brachte (was natürlich auch noch nichts zu sagen hat):
If (doc.IsValid = True) And (Isarray (doc.Items)) True Then
Mit Torstens Posting scheint sich dies zu decken. Auch die Reihenfolge Isvalid / Isarray is wegen der Abarbeitung wichtig - wenn schon Isvalid auf die Nase fällt, würde Isarray erst recht scheitern, wird aber schon nicht mehr ausgeführt.
HTH,
Bernhard
PS: Aus der Frotzelei ist ja nun noch was wirklich wichtiges geworden ;)