2016-11-12 50 views
1

我有這樣的用戶定義的數據類型返回用戶數據類型的數組dymamic:如何用LotusScript funtion

Type Image 
    Filename As String 
    Label As String 
End Type 

而且我想創建一個可以返回圖像陣列功能。到目前爲止,我已經創造了這個:

Function GetImages() As Variant 
    Dim images(1) As Image 

    Dim image0 As Image 
    image0.Filename = "test0.txt" 
    image0.Label = "test0" 

    Dim image1 As Image 
    image1.Filename = "test1.txt" 
    image1.Label = "test1" 

    images(0) = image0 
    images(1) = image1 

    GetImages = images 
End Function 

行 「GetImages =圖片」 給我這個編譯錯誤:對類型不匹配:IMAGES

任何想法?

回答

1

您不能將類型數組轉換爲變體。

使用Class代替Type

Class Image 
    Public Filename As String 
    Public Label As String 
End Class 

Function GetImages() As Variant 
    Dim images(1) As Image 

    Dim image0 As New Image 
    image0.Filename = "test0.txt" 
    image0.Label = "test0" 

    Dim image1 As New Image 
    image1.Filename = "test1.txt" 
    image1.Label = "test1" 

    Set images(0) = image0 
    Set images(1) = image1 

    GetImages = images 
End Function 

可以訪問類元素等類型的元件:

Dim imgs As Variant 
imgs = GetImages() 
Print imgs(0).filename 
+0

替代使用的陣列是使用列表中,尤其是如果元件的數目變化。 –