2

I have to find a way to store a series of variables - MonthYear (the key) and a counter. The purpose of this is to track the number of documents processed by Month & Year. I was thinking of a list but I am not sure how to save the data so that it is readable and able to be shown in a table at a later date. I thought about using a multi-dimensional array - someArray(1,0 to 1) and ReDim'ing it each time I start a new MonthYear and then save it back to a field on the document but am not sure how that is going to play out. Does anyone have an idea of how I can accomplish this?

The first dimension will be the MonthYear (key) and the second will be a counter that is updated every time a new document is processed.

  1. The key will be based on a field on the document being processed. How can I make sure I am updating the right key/counter combination?

  2. How can I retrieve the existing counter from the field on the document, update the counter and then replace the value?

I thought about just adding a new element (ReDim) every time a document is processed and than somehow adding up all the counters for each key and storing that in an array, but that just seems real messy. There has to be a good way to do this.

Any and all ideas will be greatly appreciated

RoyRumaner
  • 769
  • 1
  • 9
  • 29
  • The fact that we have to ask questions like this is what makes me hate LotusScript with a passion. It is a half-implemented language. – iconoclast Apr 02 '13 at 18:09
  • @iconoclast. Are you for real ? This sort of problem is not language related it's simply a case of using the right tools for the prob. So, you should be hating java by your thinking as well. Java has many times more collections/lists/maps/trees than you can poke a stick at. Much harder to determine what the right tools are to solve the problem if you have to research it as well. Although LS is not as robust as java, it's a lot easier to use than java to solve this problem.Dude, haters will hate. Get over it, LS is just another language, once you look at tech in that way you will be at peace. – angryITguy May 15 '13 at 02:47
  • @giulio: I agree with your criticisms of Java, but I'm not sure why you object to pointing out the flaws in a language, since you are criticizing Java. Please keep in mind the there are other languages besides those two. I would recommend learning some, as you might learn to appreciate what they have to offer. LotusScript is just another language, but not all languages are created equal. – iconoclast May 15 '13 at 14:13
  • @iconclast I do not object to you pointing out the flaws of any language, or LS for that matter. If you re-read what I wrote, I am pointing out YOUR flaws by mixing up your personal prejudice, (ie "hating"), towards a technology through your ignorance of how it's used. But if you don't understand that, then the number of programming languages known by me or you is irrelevant, as this argument is now bearing all the signs of rapidly diminishing returns. – angryITguy May 19 '13 at 08:47

1 Answers1

6

The simplest structure I can think of is a "List". Here is a quick example that "round trips" values with lists onto a document and back into a list. Cut and paste into an agent to test (don't forget to set the agent property's "Runtime" target to "None")

Sub Initialize
    Dim session As New notesSession
    Dim counter List As String
    Dim sValue As String
    Dim doc As notesDocument
    Dim itCounters As NotesItem
    Dim db As notesDatabase
    Dim i As Integer
    Dim vResult As Variant
    Dim vValues As Variant

    Set db = session.CurrentDatabase
    Set doc = db.CreateDocument
    Set itCounters = doc.ReplaceItemValue("counters","")

    counter("201201") = 16
    counter("201202") = 1
    counter("201203") = 10
    counter("201204") = 5

    ' print the tags
    Forall k In counter
        Print Listtag(k)
    End Forall

    ' adding the values (and tags)
    Forall k In counter
        Print "[" + Listtag(k) + "]:" + counter(Listtag(k))
        sValue = Listtag(k) + "!" + counter(Listtag(k))
        itCounters.AppendToTextList(sValue)
    End Forall

    'retrieving
    Erase counter

    Set itCounters = doc.GetFirstItem("Counters")
    vValues = itCounters.Values
    For i = 0 To Ubound(vValues)
        vResult = Split(vValues(i), "!")
        counter(vResult(0)) = vResult(1)
    Next

    Forall k In counter
        Print "[" + Listtag(k) + "]:" + counter(Listtag(k))
    End Forall

End Sub

The convenient aspect is that you declare each new item as you require (no Dim'ing). And you can access any value by a meaningful key (month and year or whatever). You can use a field name that matches key to load or just keep the values in a multivalue fields and use a specific separator like in the example. Also, when you increment, you don't have to search an array for right value to increment, you reference it based on the tag, and just increment it. I think that's as simple as it can get.

The Domino designer help has extensive info about lists. If you need to verify the existence of list elements look at the "isElement" function to.

angryITguy
  • 9,332
  • 8
  • 54
  • 82
  • Thank you. I will try that out and see where I get. After 20 years working with Notes and now XPages, I am ashamed to say I have never used a list before. Guess there is no time like the present. – RoyRumaner Apr 13 '12 at 13:20
  • 1
    Domino is like an ice-berg, 80% lurks just beneath the surface. You don't know about it until you run into it. – angryITguy Apr 19 '12 at 04:40
  • 1
    Lists are brilliant stuff. They are associative arrays, without the need of ReDimming, and you can stuff anything in them (even objects). Less convenient are the absence of an easy way to load or save a List from/to a NotesDocument, and the fact that you have to use IsElement prior to using a value. – D.Bugger Jun 28 '16 at 15:13