The cCounter class.

* 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
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)
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")

call counter.incrementCount("Treated")
end if

Call counter.incrementCount("RcdTreated")
set doc = dc.getNextDocument(doc)


end sub


About pierrekoerber
Hey, pour faire connaissance, laisse-moi un message... drop me a line.

One Response to The cCounter class.

  1. David Leedy says:

    This is a really cool idea!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: