Can I return a List from a LotusScript Function?
Solution 1
It seems you can't return a List from a Function.
You can easily wrap it in a class though and return the class.
eg.
Class WrappedList
Public list List As Variant
End Class
Function myfunc() As WrappedList
Dim mylist As New WrappedList
mylist.list("one") = 1
mylist.list("two") = "2"
Set myfunc = mylist
End Function
Answer was found here: LotusScript's List bug strikes again
Solution 2
This works fine for me. I've set one value to string and the other to integer so you can see that the variants behave themselves.
Sub Initialize
Dim mylist List As Variant
Call myfunc(mylist)
Msgbox "un = " + mylist("one")
Msgbox "deux = " + cstr(mylist("two"))
End Sub
Sub myfunc(mylist List As Variant)
mylist("one") = "1"
mylist("two") = 2
End Sub
Solution 3
Simply put you gotta have a function that returns a variant. I can see that you like to do it in an object oriented fashion, but if you just want to "get it done" procedurally is the easiest.
Although there are a couple of ways to do this, this is my preferred way. Note that you can create a list of any primitive data type, (ie string, variant, integer, long etc).
Function myfunc as variant
dim mylist list as variant
mylist("somename") = "the value you want to store"
mylist("someothername") = "another value"
myfunc = mylist
End Function
To use myfunc ..
sub initialise
dim anotherlist list as variant
anotherlist = myfunc
end sub
You can add parameters to myfunc if you need to by simply defining myfunc this way
function myfunc(val1 as variant, val2 as variant) as variant
You call it the same ways with parameters like this
anotherlist = myfunc("a value", "another value")
Note that "variant" is your universal datatype. What's important is that myfunc as a variant is the only way you can return lists and variants from a function.
Related videos on Youtube
mrmaan4u
Senior Analyst Programmer Currently working with AngularJS and TypeScript Previous experience with C#, Lotus Domino, Java, and Python
Updated on April 16, 2022Comments
-
mrmaan4u about 2 years
I want to return a List from a Function in LotusScript.
eg.
Function myfunc() List As Variant Dim mylist List As Variant mylist("one") = 1 mylist("two") = "2" myfunc = mylist End Function Dim mylist List As Variant mylist = myfunc()
Is this possible?
If so, what is the correct syntax?
-
iconoclast about 11 yearsThis is one example of how Lotus Notes/Domino kills you with a thousand paper cuts....
-
-
user2808054 almost 7 yearsGood answer! +1 but.. Ugh, I hate variants! You could define the class as having Public list List As NotesDocument (for example - could be any class / type) . That way when you do a foreach x in wrappedList.list .. End For, on the list, the index variable will have a type. Otherwise if you leave it as variant, you vget no typeahead from Notes Designer because it's a variant