set view = db.GetView("$all") set doc = view.GetFirstDocument() while not (doc is nothing) ' do something... set doc = view.GetNextDocument(doc) wend
Point b) and c) are harmful when they work together.
dim s as new NotesSession dim entry as NotesEntry set entry = s.CurrentDatabase.ACL.GetFirstEntryThe entry object will be reclaimed right after the assignment statement is executed as the ACL object is not stored in any variable and thus destructed, which causes the child object ACLEntry to be reclaimed. The issue in this case can be fixed by storing the ACL object in a variable.
Sub Initialize Dim s As New NotesSession Dim view As NotesView Set view=TestObj() Print view.Name End Sub Function TestObj As NotesView Dim s As New NotesSession Dim db As NotesDatabase Set db=s.Getdatabase(s.Currentdatabase.Server, "log.nsf") Set TestObj=db.Getview("UsageByUser") End functionThe View object returned by the function TestObj is reclaimed before it can be used by the caller because the parent database log.nsf is reclaimed after the function ends. If the view is from the current database, it will keep alive, even if the current database object is not initialized in the caller. The current session and database objects keep alive until the whole program e.g. agent exits. To avoid the failure above, a global variable can be declared to hold the exterior database object.
Sub Initialize Dim s As New NotesSession ‘the following two lines are optional Dim db As NotesDatabase Set db=s.Currentdatabase Dim view As NotesView Set view=TestObj() Print view.Name End Sub Function TestObj As NotesView Dim s As New NotesSession Set TestObj=s.Currentdatabase.Getview("All") End function