我有一个2级别的视图。如何获得每个第二级别类别的第一个和最后一个条目?问题是我想遍历视图中的每个条目,因此我没有使用任何GetAllEntriesByKey。如果我正在使用GetAllEntriesByKey,那么它更容易,因为从结果条目集合中,我可以将它与GetFirstEntry和GetLastEntry一起使用。但问题是我没有使用任何密钥,我想循环遍历整个视图。我已经尝试了以下但是我总是在第一次运行的评论和第一次运行失败的行中获得“对象变量未设置”。从来没有遇到'对象变量未设置',代码是'循环'。通常仅在GetNextDocument上,如果先前的文档已被删除。
Dim s As New NotesSession, db As NotesDatabase
Dim vw As NotesView, vec As NotesViewEntryCollection
Dim ve As NotesViewEntry, doc1 As NotesDocument, doc2 As NotesDocument
Set db = s.Currentdatabase
Set vw = db.Getview("View with 2 level category")
Set vec = vw.Allentries
Set ve = vec.Getfirstentry()
Do While ve.Document.Universalid <> vec.Getlastentry().Document.Universalid
Do
Set ve = vec.Getnextentry(ve)
Loop Until ve.Iscategory = False
Set doc1 = ve.Document
Do While ve.Iscategory = False
Set ve = vec.Getnextentry(ve)
Loop 'always get object variable not set here
Set doc2 = ve.Document
Print doc1.UserDepartment(0)
Print doc2.UserDepartment(0)
Set ve = vec.Getnextentry(ve)
Loop
答案 0 :(得分:2)
我根本不明白,你想要实现的目标......但是:
使用NotesViewNavigator类循环浏览所有内容。
Dim ses as New NotesSession
Dim db as NotesDatabase
Dim viw as NotesView
Dim viwNav as NotesViewNavigator
Dim veCat as NotesViewEntry
Dim veCatNext as NotesViewEntry
Dim veDoc as NotesViewEntry
Set db = ses.CurrentDatabase
Set viw = db.Getview("View with 2 level category")
Set viwNav = viw.CreateViewNav
Set veCat = viwNav.GetFirst()
While not veCat is Nothing
Set veCatNext = viwNav.GetNextCategory()
If veCatNext.IndentLevel < veCat.IndentLevel '- This is a subcategory of the given category
'- do whatever you want
'- e.g. build a new viewnavigator from this using viw.CreateViewNavFromChildren
'- or get the first document by set veDoc = viwNav.getNextDocument( veCat )
Elseif veCatNext.IndentLevel = veCat.IndentLevel '- This is the same (sub)category
Else '- we are back to the next main category
End If
Set veCat = veCatNext
Wend