Reputation: 89
I don't know if this is even possible. I want to create a set of arrays, each on named after the values that are in another array. ie: cat(0) "TRENDS" cat(1) "OPPORTUNITIES" cat(2) "TARGET ACCOUNTS" cat(3) 'ACCOMPLISHMENTS" cat(4) "LOST SALES"" cat(5) "QUOTES"
Based on this return I want to create arrays for each value above. ie: TRENDS(0) OPPORTUNITIES(0) TARGETACCOUNTS(0) ACCOMPLISHMENTS(0) LOSTSALES(0) QUOTES (0)
Note that the values that are returned in the cat array may changed so hard coding array names not viable.
I've searched for code to do this to no avail. Anyone has any ideas or code on how to do this.
Thanks in advance.
Mike
Upvotes: 0
Views: 108
Reputation: 14628
You can actually use the NotesItem class for this. E.g., you create a dummy NotesDocument and use it as a container for your arrays like this:
dim s as new NotesSession
dim myArrays as NotesDocument
dim item as NotesItem
set myArrays = new NotesDocument(s.currentDatabase)
ForAll name in cat
set item = new NotesItem(myArrays,name,"")
end ForAll
Assuming the values in the cat() array that you had in the question text, you now can access these arrays through the NotesDocument and NotesItems using the shorthand notation:
' get the nth element
dim x as string
x = myArrays.Trends(n)
' set the nth element
myArrays.Opportunities(n) = "some value"
' assign the entire array
dim someArray(50) as integer
' code to initialize someArray here
myArrays.TargetAccounts = myArray
' loop through the array
For i = 0 to ( ubound(myArrays.Quotes) - 1)
x = myArrays.Quotes(i)
Next
etc.
etc.
You never have to save the myArrays document. It, and the items it contains, will be good for as long as it stays in scope in your code.
You can also use the AppentToTextList method of NotesItem and the GetItemValue and SetItemValue methods instead of using the LotusScript shorthand notation.
Also, be aware that the New method in my example code sets only the zero-eth element of each array. You can change it to set the entire array of values from a temp array that you've already loaded in memory, if you want.
You will have to be careful of data types, of course. The value argument that I used in the call to the contructor was a string in all cases. You can easily use other types, as indicated in the documentation for NotesItem.
Final caveat: this isn't as efficient as using native LotusScript arrays, but in most cases that's probably not a big concern.
Upvotes: 1
Reputation: 1641
No, variable names are set at compile time. Your best bet is to use an associative array, which in LotusScript is called a List.
Upvotes: 0