Search code examples
lotus-noteslotusscript

Lotusscript: Use variable as array name so can apply function in a loop


I am not sure if I phrased the question well. Here is what I want to accomplish.

My agent builds a series of 25 or so arrays. Arr1() and Arr(2) etc. They are dynamic as I do not know how many items they will contain.

The agent must apply several functions to each array. One simple one is a bubble sort.

So I have 25 lines of code like this:

Call bub_sort(Arr1)
Call bub_sort(Arr2)
etc.

For each function I have 25 lines of code like that (or similar code).

Over time I will add additional arrays and possibly different functions.

Seems like it would be better to Load a List or Array of the array names, and then iterate over that for the functions, like so

'Sort Arrays
ForAll lst In lstGrpNme
    Call bub_sort(lst)
End Forall 

However, the code of course doesn't work as I am passing the string, not an array.

How can I get around this?

I fear that I will have to make a class?


Solution

  • This is a typical example of when a class would be very useful.

    I fear that I will have to make a class?

    Don't be afraid, classes are actually very easy. I wrote two blog entries about this a while back, take a look if you like: http://blog.texasswede.com/object-oriented-lotusscript-for-beginners-part-1/ http://blog.texasswede.com/object-oriented-lotusscript-for-beginners-part-2/

    Since you think you might add more functions later, you should build this as a class. Then you could do something like this:

    Set myArray = New MyArrayClass(arr1,arr2)
    Call myArray.bubbleSort