CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2010
    Location
    London
    Posts
    3

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Run-time error when debugging VB6 project from Excel VBA

    Try this:

    Code:
    Dim f As NEW Foolib.IFoo
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Nov 2010
    Location
    London
    Posts
    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...

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Run-time error when debugging VB6 project from Excel VBA

    Then, you'll need to change that!
    Code:
    IFoo is PublicNotCreatable
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Nov 2010
    Location
    London
    Posts
    3

    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?

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Run-time error when debugging VB6 project from Excel VBA

    Probably running under a different account
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Feb 2016
    Posts
    1

    Re: Run-time error when debugging VB6 project from Excel VBA

    Quote Originally Posted by Bei Ji Xiong View Post
    (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.

    Quote Originally Posted by Bei Ji Xiong View Post
    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

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    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
  •  





Click Here to Expand Forum to Full Width

Featured