Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to use .NET classes from Visual Basic 6?

At my workplace I'm stuck with Visual Basic 6, but after reading the answer to "How do I sort arrays using vbscript?" I got my hopes up, that at least some of the missing VB6 features can be supplemented by .NET features. (Different kinds of collections, mostly)

It seems, that at least some .NET classes are available for scripting and can be used from VB6 through CreateObject. But I get a distinct to-good-to-be-true feeling, so...

  • Are there any pitfalls I might encounter? (Besides that .NET has to be installed)
  • Are all .NET classes available through CreateObject?
  • Is there any way to import those classes into my VB6 project, so I can have IntelliSense?
  • Do you have any general suggestions regarding this approach?
like image 372
Daniel Rikowski Avatar asked Dec 18 '08 07:12

Daniel Rikowski


3 Answers

There's lot's of information available at the VB Fusion Developer Center on MSDN. Of particular interest will be Using the .NET Framework Class Library from Visual Basic 6 and Can I Interest You in 5000 Classes?.

You'll need to write some code in .NET to use the techniques described in the articles. If you don't already have Visual Studio 2008, you can download Visual Basic 2008 Express for free.

like image 121
Rob Windsor Avatar answered Oct 13 '22 10:10

Rob Windsor


From working on the conversion for my company CAD/CAM application. I do not recommend going from the bottom up i.e replacing the core DLL or adding core functionality thru .NET.

I had much better results working from the top down starting by replacing forms and working my way down into the Core DLL.

The biggest hurdle was providing a suitable printer and graphics interface. But Microsoft release of a Printer Compatibility Kit solved both problems. Luckily when .NET was but a glimmer on the horizon I put all the VB6 centric graphic and printing calls behind a interface.

Again start by replacing the format with a .NET assembly calling your COMM core libraries.

If your logic is intertwined with the forms I strongly recommend separating it out into a new COM DLL IN VISUAL BASIC SIX. Have the new DLL interact with the Form through a interface. The form will be a thin shell passing events to the DLL and executing various operation (drawing, re-arranging, etc0.

If you can't avoid using .NET assembly to provide new functionality then create a series of well defined and limited interfaces to control the interaction between the .NET side and the VB6/COM side.

For example we wanted to add office/job management software for our industry to the range of software we sell. We decided to implement using the .NET framework. It had to interact with our CAD/CAM software and so we create a series of interfaces where each can pull needed information or trigger action from the each other.

Finally if .NET classes are implement COM Interfaces the big gotcha is that you need to make sure that any parameters that are part of properties in COM must be declared ByVal or .NET will not be able to implement the property and fail to implement the interface. This includes the value parameter of a Let or Set

like image 38
RS Conley Avatar answered Oct 13 '22 10:10

RS Conley


Maybe this is helpfull:

By using the available information many of the classes found in the MS .NET mscorlib.dll have been reproduced in Visual Basic 6. This it NOT an implementation of the CLI runtime, only some of the unitlity classes that are in the mscorlib.dll library file.

like image 23
dummy Avatar answered Oct 13 '22 09:10

dummy