November 3rd, 2010, 12:54 PM
Run-time error when debugging VB6 project from Excel VBA
I am having a problem debugging some legacy VB6 code in our systems. The VB6 project produces an ActiveX DLL which is used by a small piece of Excel VBA code. The problem is that I get different behaviors in debug or "stand-alone" execution (i.e. it works fine as a stand-alone, but not while debugging).
I tried boiling down the problem to something smaller that generates the same error.
The VB6 project is called "FooLib", in "FooLib.vbp. It makes an AxtiveX DLL.
There are 3 class modules in it:
(1) IFoo in IFoo.cls, which is PublicNotCreatable
Public Property Get value() As Double
(2) Foo in Foo.cls, which is Private
Private myValue As Double
Public Sub build(v As Double)
myValue = v
Private Property Get IFoo_value() As Double
IFoo_value = myValue
(3) FooFac in FooFac.cls, which is GlobalMultiUse.
Public Function getFoo(v As Double) As IFoo
Dim res As Foo
Set res = New Foo
Set getFoo = res
The Excel workbook "TestFoo.xls" has a single module with this sub:
Public Sub test()
Dim f As Foolib.IFoo
Set f = Foolib.getFoo(1)
Debug.Print f.Value ' Should print 1 in the immediate window.
I do these 2 experiments:
(1) If I compile FooLib, and set FooLib.dll as a reference in the VBA environment of TestFoo.xls, then it all runs fine.
(2) If I set the reference to FooLib.vbp, and from VB6 do Run -> Start with full compile, then I get:
"Run-time error '98': A property or method call cannot include a reference to a private object, either as an argument or as a return value".
If I set a breakpoint in FooLib.getFoo, I can see that the function gets executed all the way through, and the error is after the "End Function".
I assume that the "private object" in the error message is the variable res declared as a Foo in FooLib.getFoo(). However, it is returned as an IFoo, which is PublicNotCreatable, so shouldn't it be ok to send it to Excel?
Or is the problem with the way I use the project for debugging? Or is there something I should be careful about with the registration? I am really running out of ideas to explain what is happening...
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!