<Resolved - there was a logic error after all - the “GetNextEntry” calls were not passing the correct NotesViewEntry - but it still worked 98% of the time, because the one that was passed also would have the right answer in 98% of the cases. Apologies to anyone who wasted time on this.>Original Post:
As usual, I am charged with untangling the problems of someone else’s code. Sometimes, at a certain point in a nightly agent, it seems all the remaining entries in my ViewEntryCollection are gone, or invalid! Later they are back and valid!
Could it be that the view is being recalculated at that moment? Or that the database is being compacted?
It works fine about 98% of the nights, but sporadically this problem occurs. So the debugger is unlikely (2%) to show anything.
In this program, the VEC is set by
Set VEC = MyNotesView.AllEntries .
The view is always the same view, and, the view is not categorized at all. None of the documents ever ought to be responses, and, none ought to be deleted during the run.
ObjectA loops through the VEC using
Set ThisEntry = VEC.GetFirstEntry() and
Set ThisEntry = VEC.GetNextEntry(ThisEntry)
As it goes, ObjectA gathers the VEs into a subcollection.
At certain points (changes in column values), ObjectA passes the sub-collection to ObjectB, another object in another user-defined class, by executing ObjectB.Process(SubCollection). (After Process() returns, ObjectA starts a new subcollection, loops onward, and eventually calls Process() again)
ObjectB processes the whole sub-collection in a loop. At the end of the loop, using the last VE in the sub-collection, it calls
ObjectA.MyGetNextEntry(VE_Last).
Both loops check for validity by testing NotesViewEntry.IsValid and NotesViewEntry.IsResponse, and loop to the next one if the VE fails one of these tests. MyGetNextEntry also does the same tests (using the same function), and loops until it finds a good one. 2% of the time, MyGetNextEntry is falsely returning Nothing - as if there were no more good entries in VEC. But there are!
It appears that one of three illogical things is happening:
Either
----VEC.GetNextEntry(ThisEntry) returns Nothing, and later, returns something, for the same ViewEntry; or,
—ThisEntry.IsValid is false for all remaining VEs in the VEC, but later, that is not so; or,
----ThisEntry.IsResponse is true for all remaining VEs in the VEC, but later, that is not so.
The odd result occurs as ObjectB calls a method in ObjectA to see if anything is left. (ObjectA is the only one that has the entire VEC.) The call is in a method of ObjectB that was called from a method of ObjectA. That is, ObjectA executes ObjectB.Process(), and within Process(), ObjectB calls ObjectA.MyGetNextEntry() .
After control returns from Process(), ObjectA finds that there are additional, valid NotesViewEntries in VEC after all.
All theories and WAGs are welcome - I got nothing!
TIA
Rich
PS Believe me, you do not want to read this entire code!