Reputation: 3473
The normal dynamic array supports empty (= nil, Length() = 0)
.
The variant array however does not seem to support this.
I pass my data in variant array (because of OLE/COM), and I get an error when the user defines 0 elements...
I can use varEmpty instead of a 0 length array, but these data arrays are flexible changed (add item, remove item, etc.).
How I can I pass empty arrays in a Variant, or do I need to use other way?
Upvotes: 7
Views: 920
Reputation: 1
Here is some code that will update a Variant Array whether the Array is empty or not.
Sub Variant_Add(Var_Array As Variant, What)
' Add "What" to a "Var_Array" without book keeping.
' 3/18/19 Created, Mac Lingo
' Note: Variant_Add must be defined in the following way: _
Dim Var_Array as Variant
Prog = "Variant_Add"
If IsEmpty(Var_Array) Then
ReDim Var_Array(1) As Variant
Knt = 1
Else
Knt = Var_Array(0) + 1
ReDim Preserve Var_Array(Knt) As Variant
End If
Var_Array(Knt) = What
Var_Array(0) = Knt
End Sub ' Variant_Add
Upvotes: 0
Reputation: 613013
varEmpty
is the correct way to handle this. Of course, the code on the other side of the COM interface may not like empty arrays, but that all depends on the particular contract you have with that interface.
Upvotes: 5