L
Lee Benfield
(x posted, as I'm working with excel 97, but this exibits on VB6)
When you pass an element of a variant array to a class function
(and ONLY a class function, non class function and class subs do not
exhibit this), you end up with something which looks suspiciously
like a pointer instead of the correct value. Is there a relevant KB
article for this? (can't find one).
Note that this requires at least 2 values in the paramarray.
Can anyone point me at either a fix or an explanation?
Example:
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
(note the incrementing addresses - swap array elements for predictable
behaviour!)
I've tested that this also exhibits when passing to a com server,
([vararg] [in] SAFEARRAY(VARIANT) *, [out, retval] VARIANT *)
incorrect elements end up as VT_I4 regardless of input type.
At my wits end!
Thanks.
Lee.
When you pass an element of a variant array to a class function
(and ONLY a class function, non class function and class subs do not
exhibit this), you end up with something which looks suspiciously
like a pointer instead of the correct value. Is there a relevant KB
article for this? (can't find one).
Note that this requires at least 2 values in the paramarray.
Can anyone point me at either a fix or an explanation?
Example:
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
(note the incrementing addresses - swap array elements for predictable
behaviour!)
I've tested that this also exhibits when passing to a com server,
([vararg] [in] SAFEARRAY(VARIANT) *, [out, retval] VARIANT *)
incorrect elements end up as VT_I4 regardless of input type.
At my wits end!
Thanks.
Lee.