The cCounter class. March 11, 2009
Posted by pierrekoerber in Lotus domino, Tech, programming.Tags: development, domino, Lotus domino, lotusscript, pierre koerber, programming, switzerland, valais, www.pierre-koerber.ch
trackback
* When programming a very long an complex agent it’s very fine to display the agent stats at the end of the agent’s execution. These stats could be a lot of numeric data. It’s a pain to declare and manage all these variables.
* For doing this you need to create a lot of different counters and it’s very boring to manage the init part of these counters, the increment and the display. And what a pain if you want to add a new counter…
* With my solution you will find this very easy to manage and you will add a lot of interesting counters in your next complex agent.
* The idea is to put every counter in a class which will manage for us the boring job.
* This class will init the counter, manage the increment and give us the text.
Here the code :
‘ Class counter v1.0
‘ By Pierre Koerber
Class cCounter
lCounter List As Long
Public Function incrementCount(sCounterName As String)
If Iselement(lCounter(sCounterName)) = False Then
lCounter(sCounterName) = 1
Else
lCounter(sCounterName) = lCounter(sCounterName) + 1
End If
End Function
Public Function toString() As String
Dim sRes As String
Forall x In lCounter
If sRes = “” Then
sRes = Listtag(x) + “=” + Cstr(x)
Else
sRes = sRes + “,” + Listtag(x) + “=” + Cstr(x)
End If
End Forall
toString = sRes
End Function
End Class
‘——————————-
‘ calling code, this allows you to manage three counter in a easy and cool way.
‘——————————-
sub initialize
dim counter as new cCounter()
set doc = dc.getFirstDocument
while not(doc is nothing)
if doc.Subject(0) = “” then
Call counter.incrementCount(“Err”)
else
call counter.incrementCount(“Treated”)
end if
Call counter.incrementCount(“RcdTreated”)
set doc = dc.getNextDocument(doc)
wend
log(counter.toString())
end sub
This is a really cool idea!!