Debugging a VB6 OCX in a VB6 project

Posted on 2004-11-04
Last Modified: 2008-02-01
I'm trying to debug a VB6 OCX (activeX) in a VB6 project and I can't get it working. I have the OCX and the project file. I create a new project with a blank form and add the OCX component and I can't step into it. If I open up the project and add a form and then try to debug it, it doesn't run.

Whats the correct way to debug this?
Question by:Sparky191
    LVL 9

    Expert Comment

    by:Shahid Thaika
    Do you have the source code of the ocx and the project opened along with your executable project? If yes add the following statement... 'debug.assert false' one line before the code where you want to debug. The VB compiler should break at this point.
    LVL 5

    Accepted Solution

    You need to have both projects loaded at the same time:

    Start VB.
    Open the project for your Active X Control.
    The in File Select Add Project.
    Start a new standard project.
    Right click on the new project and select Set as Startup
    make sure that the form for the Active X Control project closed (project still loaded - just close the form).
    Open the form from the new project and add the Active X control (you may need to compile the control first)
    Set your breakpoints
    Now when you run - it will allow you to enter the code of the control.

    LVL 1

    Author Comment

    I was already trying it with both projects open and the ocx on the new form, but it wouldn't step into the code. Someone elsewhere suggested I should add the vbp rather than the ocx as a component. This intially apeared as an option and then disappeared and now has reappeared so I  did that and its now working. But I didn't know about the  "Set as Startup" so I'll try that with a new project and see if it works.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now