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?
You can get a function toi return a list, just get rid of "List" bit in your function, so instead of
...do:
then you can call your function as you already do.
Lists are great and I use them all the time, but I have found one limitation with lists...
if if have a function like:
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).
To use myfunc ..
You can add parameters to myfunc if you need to by simply defining myfunc this way
You call it the same ways with parameters like this
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.
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.
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.
Answer was found here: LotusScript's List bug strikes again