2009-02-27 38 views
4

LotusScriptの関数からリストを返したいとします。LotusScript関数からリストを返すことはできますか?

例えば、

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() 

これは可能ですか?

もしそうなら、正しい構文は何ですか?

+1

これは、ロータスノーツ/ドミノがあなたに何千枚もの紙切れを与える方法の一例です。 – iconoclast

答えて

2

これは私にとってうまくいきます。私は文字列に1つの値を設定し、整数にもう1つの値を設定しました。そのため、バリアントが動作することがわかります。

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 
8

関数からリストを返すことはできないようです。

あなたは簡単にクラスにラップしてクラスを返すことができます。

例えば、

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 

回答がここに発見された:LotusScript's List bug strikes again

+0

かなり明るいです。 – iconoclast

+0

良い答え! +1だけど、うん、変種が嫌い!クラスをパブリックリストのList As NotesDocument(たとえば、任意のクラス/タイプ)として定義することができます。そのようにして、foreach xをwrappedList.list .. Endで実行すると、リストのindex変数には型があります。そうでない場合は、バリアントとして残しておくと、Notes Designerからの先取りはありません – user2808054

0

あなたは自分の機能に「リスト」ビットを取り除くTOIはリストを返す関数を得ることができますので、代わりの

Function myfunc() List As Variant 
    ... 
End Function 

。 ..do:

Function myfunc() As Variant 

あなたが既に行ったようにあなたの関数を呼び出すことができます。

Public Function returnMyList() as Variant 

    Dim myList List as Variant 
    Dim s_test as String 
    Dim i as Integer 
    Dim doc as NotesDocuemnt 
    Dim anotherList List as String 

    '// ...set your variables however you like 

    myList("Some Text") = s_text 
    myList("Some Integer") = i 
    myList("Some Doc") = doc 

    '// If you returned the list here, you're fine, but if you add 
    '// another list... 
    anotherList("one") = "" 
    anotherList("two") = "" 
    myList("Another List") = anotherList 

    '// This will cause an error 
    returnMyList = myList 

    '// I bodge around this by writting directly to a List 
    '// that is set as global variable. 

End Function 
1

簡単にあなたを置く:のような機能を持っている場合場合

Dim mylist List As Variant 
mylist = myfunc() 

リストは素晴らしいですし、私は彼らにすべての時間を使用しますが、私はリストを1つの制限が発見した...

バリアントを返す関数が必要です。私はあなたがオブジェクト指向のやり方でそれをやりたがっているのを見ることができますが、手続き的に "完了させる"ことが一番簡単です。

これを行うにはいくつかの方法がありますが、これが私の好みの方法です。任意のプリミティブデータ型(文字列、バリアント、整数、longなど)のリストを作成することができます。

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 

myfunc関数を使用するには...

sub initialise 
    dim anotherlist list as variant 
    anotherlist = myfunc 
end sub 

あなたは、単にてmyfuncこのよう

function myfunc(val1 as variant, val2 as variant) as variant 

を定義することで、必要がある場合は、パラメータと同じ方法でそれを呼び出すMYFUNCするパラメータを追加することができますこのように

anotherlist = myfunc("a value", "another value") 

"variant"は汎用データ型です。重要なのは、myfuncをバリアントとして使用することが、関数からリストとバリアントを返すことができる唯一の方法だということです。

関連する問題