Run-time error when debugging VB6 project from Excel VBA
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

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

  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
    Chicago, IL
    Posts
    14,951

    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
    Chicago, IL
    Posts
    14,951

    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
    Chicago, IL
    Posts
    14,951

    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!

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center