-
November 3rd, 2010, 11:54 AM
#1
Run-time error when debugging VB6 project from Excel VBA
Hi there,
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
End Property
(2) Foo in Foo.cls, which is Private
Private myValue As Double
Implements IFoo
Public Sub build(v As Double)
myValue = v
End Sub
Private Property Get IFoo_value() As Double
IFoo_value = myValue
End Property
(3) FooFac in FooFac.cls, which is GlobalMultiUse.
Public Function getFoo(v As Double) As IFoo
Dim res As Foo
Set res = New Foo
res.build v
Set getFoo = res
End Function
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.
End Sub
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...
Nicolas
-
November 3rd, 2010, 11:59 AM
#2
Re: Run-time error when debugging VB6 project from Excel VBA
Try this:
Code:
Dim f As NEW Foolib.IFoo
-
November 3rd, 2010, 12:08 PM
#3
Re: Run-time error when debugging VB6 project from Excel VBA
Thanks for the very quick reply!
Do you mean that I should replace
[code]
Dim f As Foolib.IFoo
[\code]
with
[code]
Dim f As NEW Foolib.IFoo
[\code]
in the Excel VBA project? That is not working, but it's understandable why: IFoo is PublicNotCreatable, so I can't use it with new. I do get a "Compile error: Invalid use of New keyword" in VBA...
-
November 3rd, 2010, 02:42 PM
#4
Re: Run-time error when debugging VB6 project from Excel VBA
Then, you'll need to change that!
Code:
IFoo is PublicNotCreatable
-
November 3rd, 2010, 06:09 PM
#5
Re: Run-time error when debugging VB6 project from Excel VBA
Is there a way to do that *and* hide from the client the concrete type returned by the function? (The way things are currently, because Foo is Private, the client cannot see it).
Anyway, why would the behavior be different in debug vs "standalone" execution?
-
November 3rd, 2010, 07:28 PM
#6
Re: Run-time error when debugging VB6 project from Excel VBA
Probably running under a different account
-
February 11th, 2016, 06:18 AM
#7
Re: Run-time error when debugging VB6 project from Excel VBA
 Originally Posted by Bei Ji Xiong
(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".
I believe that with the second approach you're having two different processes (VB6 IDE and Excel) and your trying to pass a reference of an object between them.
 Originally Posted by Bei Ji Xiong
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...
So the problem is the way you use the project for debugging.
Check below:
http://stackoverflow.com/questions/5...basic-6-active
https://msdn.microsoft.com/en-us/library/Aa716186
-
February 19th, 2016, 04:13 PM
#8
Re: Run-time error when debugging VB6 project from Excel VBA
tavaresilva, thank you for your eagerness and willingness to help out. Just remember, this particular thread is almost 6 years old and I suppose the problem has long been solved. Please do not reply to ancient threads. Let sleeping dogs lie There are so many current issues that need solving and by the looks of it, you are quite able to help out.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|