2 回答
TA贡献1856条经验 获得超17个赞
'方法1
Function GetCollection1() As Collection
Dim col As Collection
Set col = New Collection
col.Add "信息1"
col.Add "信息2"
Set GetCollection1 = col
Set col = Nothing
End Function
'方法2
Sub GetCollection2(col As Collection)
Set col = New Collection
col.Add "信息3"
col.Add "信息4"
End Sub
Private Sub Command1_Click()
Dim a As Collection
Dim b
Set a = GetCollection1
For Each b In a
Debug.Print b
Next
Call GetCollection2(a)
For Each b In a
Debug.Print b
Next
End Sub
TA贡献1853条经验 获得超18个赞
Private Type ABC '自定义数据类型
arr() As Variant '数组
a As New Collection '集合
End Type
Private Function f() As ABC '函数返回值是自定义类型
ReDim f.arr(3) '定义数组上界
For i = 0 To UBound(f.arr)
f.arr(i) = i '数组赋值
Next i
f.a.Add "信息1" '集合赋值
f.a.Add "信息2"
End Function
Private Sub Form_Click()
Dim x As ABC
x = f '调用函数
For i = 0 To UBound(x.arr)
Print x.arr(i) '输出数组
Next i
For Each i In x.a
Print i '输出集合
Next
End Sub
- 2 回答
- 0 关注
- 717 浏览
添加回答
举报