IBM®
Skip to main content
    Country/region select      Terms of use
 
 
   
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks  >  Lotus  >  Forums & community  >  Best Practice Makes Perfect

Best Practice Makes Perfect

A collaboration with Domino developers about how to do it and how to get it right in Domino

Recently got a question about the NotesView.TopLevelEntryCount method, and I had to do a little research to answer it well. Here's what I found:

  • Bottom line: don't use this property for views that might possibly contain lots of documents. For best performance, you might not want to use it at all unless the view is known to be very small. The same applies to the Java version of the property.
  • It returns an Integer, which in LotusScript is always signed. For numbers between 32768 and 65535, inclusive (0x8000 to 0xFFFF) the result appears to be a negative number.
  • If there are more than 65536 entries, it doesn't throw an error, but just returns the low-order word of the actual count.
  • If you know there are fewer than 65536 entries in the view, you can test whether the result is negative and if so, add 65536 to get the real value.
  • As you might imagine, the number of cases where you are unsure that there are fewer than 32768 entries but sure there will never be more than 65536, is fairly limited.
  • Reading this property is fairly slow, for large views.
Here's a way that works reliably and is efficient for views of any size. I'm adding it to my personal library of useful functions; you might want to do the same.

Function TopEntryCount(vu As NotesView) As Long
     
' return the number of top-level entries in a view.
      Dim nav As NotesViewNavigator, ent As NotesViewEntry

      Set nav = vu.CreateViewNav

      Set ent = nav.GetLast

      TopEntryCount = Clng(Strtoken(ent.GetPosition("."), ".", 1))

      If ent.IsTotal Then

             
' if the view has a totals row, we might not want to count it.
              TopEntryCount = TopEntryCount - 1

      End If

End Function

This is actually a lot faster than the built-in property, and you might want to use it even for views well below the size limit. The Java API goes to the same back-end functions, so while I didn't specifically test it, I assume performance is similar in that case.

Andre Guirard | 26 May 2010 11:20:35 AM ET | | Comments (1)

Search this blog 

Disclaimer 

    About IBM Privacy Contact