5

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

これは可能ですか?

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

4

4 に答える 4

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
于 2009-02-27T04:50:11.970 に答える
1

リストを返す関数を取得できます。関数の「リスト」ビットを削除するだけなので、代わりに

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

...行う:

Function myfunc() As Variant

その後、すでに行っているように関数を呼び出すことができます。

Dim mylist List As Variant
mylist = myfunc()

リストは素晴らしく、私はいつもそれらを使用していますが、リストには1つの制限があります...

次のような機能がある場合:

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
于 2009-05-27T07:23:55.643 に答える
1

簡単に言えば、バリアントを返す関数が必要です。オブジェクト指向の方法でそれを行うのが好きなのはわかりますが、手続き的に「完了」したい場合は最も簡単です。

これを行うにはいくつかの方法がありますが、これが私の好みの方法です。任意のプリミティブ データ型のリストを作成できることに注意してください (つまり、string、variant、integer、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 を定義するだけで、必要に応じて myfunc にパラメーターを追加できます。

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

このようなパラメーターを使用して同じ方法で呼び出します

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

「バリアント」はユニバーサルデータ型であることに注意してください。重要なのは、バリアントとしての myfunc が、関数からリストとバリアントを返す唯一の方法であることです。

于 2009-12-30T11:38:28.630 に答える