Whilst most modern programming languages support an away to initialize an array in a single statement, LotusScript does not have a simple way of creating an array and assigning values to elements in the array.
The creation and initialization of an array typically requires code similar to the following:-
Dim Month(12) As String
Month(1) = "JAN"
Month(2) = "FEB"
...
Month(12) = "DEC"
Whilst split is an option, it does not work for numbers and dates. Eventually this bugged me enough that I searched for a way to initialize an array such as the above in a single statement. To make my code "easy" to read I have created an Array function which takes a string and evaluates it using @Formulae (which does allow a "List" to be assigned).
I can now write a single LS statement such as
Months = Array({"JAN":"FEB":"MAR":"APR":"MAY":"JUN":"JUL":"AUG":"SEP":"OCT":"NOV":"DEC"})
This works for text, numeric, and date values (but not complex data objects).
The code for the Array function is as follows:-
'/**
' * Returns an array populated with initial values
' *
' * @author Peter Presnell
' * @param Source The initial values separated by colon
' * @return An array created from the initial values
' */
Function Array(Source As String) As Variant
Dim MyArray(0) As String
Try:
On Error Goto Catch
Array = Evaluate(Source$)
Exit Function
Catch:
Stop
MyArray(0) = Source$
Array = MyArray
Exit Function
End Function