Debugging VB.NET code from VB6

Hi !. This is my first programming related post on my blog. I will keep posting more programming posts based on my experience and knowledge.

In project based companies new technologies are easily adopted but this is not the case with Product based companies. Once the product is developed they have to stick with the language for years with which they developed it. Converting a product into a different programming language involves lots of development costs and this is not feasible every time.

Microsoft has done a good job by introducing Interop Toolkit. We can now develop new modules in .NET and use them in VB6. In this way we can use many good features provided by .NET. Here we use two languages .NET and VB6. So the debugging becomes little tricky, but it's not a big deal.

Debugging VB.NET code from VB6 is no different than debugging any other Visual Basic 6.0 project. Press F5 to run, attach VB6 process in VB.NET IDE, set breakpoints, and debug as you normally would.

Follow these steps to debug your .NET code:
  1. Load your .NET project in Visual Studio 2005.
  2. Build the .NET project if it has not already been built.
  3. Load your Visual Basic 6.0 code in the Visual Basic 6.0 IDE.
  4. Run your application by pressing F5 in the Visual Basic 6.0 IDE (Note: You must do this once before attaching the .NET debugger to properly load the .NET code).
  5. In Visual Studio .NET 2005, select Attach to Process... from the Tools menu.
  6. In the dialog that appears, select the VB6.exe process (Note: because the Visual Basic 6.0 code runs within the Visual Basic 6.0 IDE, you must select this process to debug).
You only need to repeat the steps above after rebuilding .NET code. The Visual Basic 6.0 IDE must be closed when rebuilding. After completing these steps, press F5 in the Visual Basic 6.0 IDE to run, set breakpoints, and debug as you normally would.

There is also an another way for debugging. Instead off attaching the vb6.exe process everytime you can configure settings in Project properties to run external program while debugging.

Follow these steps:
  1. Go to the Project properties window and select Debug tb.
  2. In Start Action section select Start external program and type the path of vb6.exe. e.g. C:\Program Files\Microsoft Visual Studio\VB98\VB6.EXE.
  3. In Command line arguments type the vb6 project path. e.g. "D:\Test Projects\Project1.VBP".
  4. Save the settings, set the break proints and press F5.

This will open the VB6 project. Press F5 to run and start debugging.

No comments: