benf.org : other : vb6paramarraybug |
I put this up for info, as I can't find another mention of it, and MS don't seem to be aware.......
deep breath... If you pass an element of a variant array into a class object method which returns a value (i.e. class object function), and which has a paramarray in its argument list, (and you pass at least two values)... you end up with what looks suspiciously like a pointer. (aaannd breathe...) You certainly don't get the value you were after. Eg:
>> module:========
Private Sub showbug()
Dim ca As clsA
Set ca = New clsA
Dim v
v = Array(1, 2, 3, 4)
Call ca.testSub(v(0), v(1), v(2), v(3))
Call ca.testFn(v(0), v(1), v(2), v(3))
call ca.testFn(v(2))
End Sub
clsA:==========
Public Sub testSub(ParamArray foo() As Variant)
Debug.Print Join(foo, ",")
End Sub
Public Function testFn(ParamArray foo() As Variant) As Variant
Debug.Print Join(foo, ",")
testFn = "Oops"
End Function
<<==============
Output:
1,2,3,4
1556816,1556832,1556848,1556864
3
Niiiiice....