我试着用了一个集合 dim a as new collection 然后在这个集合里面添加我要的返回值 a.add " 信息1" a.add "信息2" ················· ,那 能不能让这个函数的返回值是 a这个集合, 我想在其他地方调用这个函数,然后判断 函数返回的 a集合 里面的值 ,如何返回个集合
大话西游666
浏览 718回答 2
2回答
慕慕森
'方法1Function GetCollection1() As CollectionDim col As CollectionSet col = New Collectioncol.Add "信息1"col.Add "信息2"Set GetCollection1 = colSet col = NothingEnd Function'方法2Sub GetCollection2(col As Collection)Set col = New Collectioncol.Add "信息3"col.Add "信息4"End SubPrivate Sub Command1_Click()Dim a As CollectionDim bSet a = GetCollection1For Each b In aDebug.Print bNextCall GetCollection2(a)For Each b In aDebug.Print bNextEnd Sub
Private Type ABC '自定义数据类型arr() As Variant '数组a As New Collection '集合End TypePrivate Function f() As ABC '函数返回值是自定义类型ReDim f.arr(3) '定义数组上界For i = 0 To UBound(f.arr)f.arr(i) = i '数组赋值Next if.a.Add "信息1" '集合赋值f.a.Add "信息2"End FunctionPrivate Sub Form_Click()Dim x As ABCx = f '调用函数For i = 0 To UBound(x.arr)Print x.arr(i) '输出数组Next iFor Each i In x.aPrint i '输出集合NextEnd Sub