如何在 Lotusscript 函数中 return 用户数据类型的动态数组
How to return a dymamic array of user data types in Lotusscript funtion
我有这个用户定义的数据类型:
Type Image
Filename As String
Label As String
End Type
我想创建一个可以 return 图像数组的函数。到目前为止,我已经创建了这个:
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"行给我这个编译错误:类型不匹配:IMAGES
有什么想法吗?
您不能将类型数组转换为变体。
使用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
您可以访问 class 个元素,例如类型元素:
Dim imgs As Variant
imgs = GetImages()
Print imgs(0).filename
我有这个用户定义的数据类型:
Type Image
Filename As String
Label As String
End Type
我想创建一个可以 return 图像数组的函数。到目前为止,我已经创建了这个:
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"行给我这个编译错误:类型不匹配:IMAGES
有什么想法吗?
您不能将类型数组转换为变体。
使用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
您可以访问 class 个元素,例如类型元素:
Dim imgs As Variant
imgs = GetImages()
Print imgs(0).filename