Variant array element -> class object (or com server) paramaray function = pointer, not value?
From: Lee Benfield (lee_at_sp_benf_am.org)
Date: 05/21/04
- Previous message: johnny e: "Add new CommandBar in VBA editor"
- Next in thread: Ken Halter: "Re: Variant array element -> class object (or com server) paramaray function = pointer, not value?"
- Reply: Ken Halter: "Re: Variant array element -> class object (or com server) paramaray function = pointer, not value?"
- Reply: Pásztor, Zoltán: "Re: Variant array element -> class object (or com server) paramaray function = pointer, not value?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 21 May 2004 21:55:00 +0100
(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:
>> 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
(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.
- Previous message: johnny e: "Add new CommandBar in VBA editor"
- Next in thread: Ken Halter: "Re: Variant array element -> class object (or com server) paramaray function = pointer, not value?"
- Reply: Ken Halter: "Re: Variant array element -> class object (or com server) paramaray function = pointer, not value?"
- Reply: Pásztor, Zoltán: "Re: Variant array element -> class object (or com server) paramaray function = pointer, not value?"
- Messages sorted by: [ date ] [ thread ]