Using Lotusscript Lists For Counters

How many times do you not want to count the number of documents you process, perhaps even a few different counters? Today I was working on a Lotusscript agent where I wanted to keep track of the total number of documents processed, as well as individual counters for a few different types of documents. Normally I would have used a handful of variables, but I realized that I could use lists for this.

This is what my old code would look like:

Dim cnt As Long
Dim totcnt As Long
Dim type1cnt as Long
Dim type2cnt as Long
Set view = claimdb.GetView("(LookupView)")
Set col = view.AllEntries
view.AutoUpdate = False
totcnt = col.Count
cnt = 0
Set entry = col.GetLastEntry()
Do While Not entry Is Nothing
    cnt = cnt + 1
    ' Do stuff here 
    If entry.ColumnValues(0) = "Type1" Then
        type1cnt = type1cnt + 1
    ElseIf entry.ColumnValues(0) = "Type2" Then
        type2cnt = type2cnt + 1
    End If
    Print "Processed " & cnt & " of " & totcnt
    Set entry = col.GetPrevEntry(entry) 
Loop

My new code would look like this:

Dim cnt List As Long
Dim doctype As String
Set view = claimdb.GetView("(LookupLargeLossSummary)")
Set col = view.AllEntries
view.AutoUpdate = False
cnt("Total") = col.Count
cnt("Processed") = 0
Set entry = col.GetLastEntry()
Do While Not entry Is Nothing
    cnt("Processed") = cnt("Processed") + 1
    ' Do stuff here
    doctype = entry.ColumnValues(0)
    cnt(doctype) = cnt(doctype) + 1
    Print "Processed " & cnt("Processed") & " of " & cnt("Total")
    Set entry = col.GetPrevEntry(entry) 
Loop

Note that the list tag is case sensitive. The example also assumes that the document type is displayed in the first column of the view. You can also use ForAll to get the values of all list elements:

ForAll c in cnt
    Print ListTag(c) & " = " & c
End ForAll

That’s it for today. Happy coding!

 

Leave a Reply