2009-02-27 3 views
4

LotusScript의 함수에서 List를 반환하고 싶습니다.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

로터스 노츠/도미노가 1,000 가지 종이 절단으로 당신을 죽이는 방법의 한 예입니다 .... – iconoclast

답변

2

나를 위해 잘 작동합니다. 하나의 값을 문자열로 설정하고 다른 하나는 정수로 설정 했으므로 변형이 자체적으로 작동하는 것을 볼 수 있습니다.

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하지만 ... 아, 변형이 싫어! 클래스를 Public List List NotesDocument (예 : 모든 클래스/유형)로 정의 할 수 있습니다. 이런 식으로 wrappedList.list .. End에서 foreach x를 할 때,리스트에서 인덱스 변수는 타입을 가질 것이다. 그렇지 않은 경우이를 변형으로 남겨두면 Notes Designer에서 변형이기 때문에 어떤 종언판도 사용할 수 없습니다. – user2808054

0

당신은 당신의 함수에서 "목록"비트를 제거 토이가 목록을 반환하는 함수를 얻을 수 있으므로 대신

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

. ..do :

Function myfunc() As Variant 

그러면 이미 수행 한 것처럼 함수를 호출 할 수 있습니다.

Dim mylist List As Variant 
mylist = myfunc() 

리스트는 중대 하 나는 그들에게 모든 시간을 사용하지만, 나는 목록을 하나의 한계를 ... 발견

같은 기능이있는 경우 경우 :

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

을 간단히 넣어 변형을 반환하는 함수가 있어야합니다. 나는 당신이 객체 지향적 인 방식으로 그것을하고 싶어한다는 것을 알 수있다. 그러나 단지 "순조롭게"하고 싶다면 절차 적으로 가장 쉬운 방법이다.

이렇게하는 데는 몇 가지 방법이 있지만,이 방법을 선호합니다. 기본 데이터 형식 (예 : 문자열, 변형, 정수, 긴 등)의 목록을 만들 수 있습니다.

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 
당신은 단순히 당신이 매개 변수를 사용하여 같은 방법을 호출

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

myfunc에이 방법을 정의하여 필요한 경우 MYFUNC하는 매개 변수를 추가 할 수 있습니다

이 같은

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

"variant"는 범용 데이터 유형입니다. 중요한 것은 myfunc를 변형으로 사용하면 함수에서 목록과 변형을 반환 할 수있는 유일한 방법이라는 것입니다.