Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I return a List from a LotusScript Function?

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?

like image 944
molasses Avatar asked Feb 27 '09 04:02

molasses


3 Answers

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

like image 134
molasses Avatar answered Oct 12 '22 04:10

molasses


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
like image 41
paxdiablo Avatar answered Oct 12 '22 05:10

paxdiablo


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.

like image 37
giuliocc Avatar answered Oct 12 '22 06:10

giuliocc