Eli_Ott
(Eli Ott)
December 20, 2013, 9:47am
1
I have a method with a ParamArray of Variants:
Sub SomeMethod(ParamArray vars() As Variant)
When I do:
AnObject.SomeMethod(True, False)
it will not compile, because this is understood by the compiler as a ParamArray of Booleans.
The only way known to me, is to write this code:
Dim args() As Variant
args.Append(True)
args.Append(False)
AnObject.SomeMethod(args)
Is this verbosity necessary, or is there a way to reduce that to a one-liner?
Eli_Ott
(Eli Ott)
December 20, 2013, 10:39am
3
Thanks, but it has to be an array of Variants, not an array of Booleans (see the method definition).
Will_Shank
(Will Shank)
December 20, 2013, 10:44am
4
It compiles for me. Are you sure nothing else is going on?
[code]Class Class1
Sub SomeMethod(ParamArray vars() As Variant)
for i As integer = 0 to vars.Ubound
MsgBox vars(i).StringValue
next
End Sub
End Class
Sub Action() //PushButton
dim AnObject As new Class1
AnObject.SomeMethod(True, False)
End Sub
[/code]
Eli_Ott
(Eli Ott)
December 20, 2013, 11:16am
5
Sorry, it is not a ParamArray, it is an array of Variants (it’s an external library, so I can’ change it to a ParamArray):
Sub SomeMethod(vars() As Variant)
Will_Shank
(Will Shank)
December 20, 2013, 12:06pm
6
ok, you can add this global method to package an array
Function ToVariantArray(ParamArray vars() As Variant) As Variant()
return vars
End Function
and then…
AnObject.SomeMethod( ToVariantArray(True, False) )
and use a better name