Migrating Code from Visual Basic 6 to .NET

Migrating Code from Visual Basic 6 to .NET
Mike Gresley

Still have your production code on VB6, eh?  I know, I know...you personally cringed in shame when I asked the question.  So, you probably don't even need the lecture: you're fully aware that running your production code on a ten-plus-year-old platform is like driving a 45-year-old car (and not a restored classic, for the record).  You get it.  I get it.  Everyone gets it.  But the crux of the matter is that you remain in this tight spot where you need to make a change, and now that change seems like it will be pretty drastic.  Well, things are not as bad as they seem.  That's not to say that you don't have some work ahead of you, but this is doable.  So pull up a virtual seat, grab a cup of joe, and let's talk.

First of all, you should forget about a magic wand that you can wave and have your code appear in a glorious explosion of rainbow light, unicorns, dragons, perfectly formatted OO concepts-based code, and other wonderful imaginary things.  There are, however, both tools and guidance from Microsoft available to you to help speed the process along.  The good news here is that you shouldn't have to recode everything from scratch.  However, you will need to spend some time on fixes, especially in areas where you've heavily leveraged deprecated functionality.  It's important to remember that the VB6 development environment doesn't enforce any sort of object-oriented concepts.  That doesn't mean you couldn't structure your code in such a way on your own, but let's face it: few of us who were ever VB6 developers really stuck to such formality.  VB6 is essentially the ultimate Swiss army knife: it does a lot of things pretty well, but doesn't insist that you be an expert with any of the tools at your disposal to use it.  It's easy to use...and most of the code written with it was purely event-driven and grew organically, as opposed to being part of a heavily structured enterprise plan.  If you can say otherwise about your shop and code, then bully for you.  That means you're ahead of the pack and your migration process should be simpler than average (in theory).

All right, so let's get down to the nuts and bolts here, shall we?  At a high level, your VB6 migration can be summarized into a mere two (largish) bullets:

1) There is no “official” migration path specified by Microsoft on converting from VB6 to C# or VB.NET, as both the structure and syntax of these languages differs significantly. However, there are several migration resources available that provide helpful advice and best practices.

a. VB6 to VB.NET Upgrade Guide

b. VB6 to VB.NET Upgrade Webcast

c. There is also a book available on the subject of VB6 migration to .NET by Mike Bond (who is a former VB development team member), Ed Robinson, and Ian Oliver: find it online here.

2) The good news is that Microsoft provides an upgrade wizard for VB6 code, and it is integrated into Visual Studio 2008 (and 2005, for that matter). This will migrate code where possible and help provide assistance on conflicts that cannot be automatically resolved. A Guide is available on how to use the upgrade wizard here and summarized help is available here.

I know what you're thinking: that's it?  Well, overall, it really is pretty straightforward.  But, you will spend a not-insignificant amount of time reading the upgrade guide and (hopefully) viewing the webcast before you even begin.  And, I strongly urge you to read the guide front-to-back before you go jumping into things with the upgrade wizard.  And, as for the wizard, I think that a good, loose rule of thumb here is that it will get you 60%-70% of the way there.  After that, you will be resolving the conflicts it has identified yourself.  But hey, that's a big jump start, and it sure beats recoding a 5,000-line app from scratch.

One other thing to keep in mind is that the guides and wizard focus on moving VB6 to VB.NET.  You may be interested in going to C# (as many people are).  However, it’s obviously logical that there are many more similarities between VB6 & VB.NET syntactically than between VB6 & C#, and thus the former is the target of all guidance and tools.  One important thing to remember is that “.NET is .NET,” meaning that the end target language for the conversion really doesn’t matter.  Once the code is compiled into .NET, it runs exactly the same regardless of what .NET language is used.  And, converted code in VB.NET can interact with new code written in C#.NET.  So, gets things converted to VB.NET, and then if you want to write new bits in C#, then go right ahead.  They play well together.

So, that's where you need to get started.  In addition, I am going to provide for you below what I believe is a fairly exhaustive list of links to practically every good resource on the subject, including third-party software and partners that can help you make this transition easier.  I'd like to thank my colleague Angela Dugan, who is a Dev Tools Evangelist at Microsoft, for compiling such a huge reference library on the subject.

To all of you working on a migration, a very sincere "best of luck."  You can do this.  And, if you run into trouble, please reach out to your support system at Microsoft or one of our partners.  If you need someone to help you along this path, that help is definitely available.


Mike Gresley


      Mike Gresley is a Developer Technology Specialist in the Public Sector division of the Developer and Platform group at Microsoft.








VB6 to .NET Conversion Resource Library:

VB6 to .NET Migration Guidance:

1) MSDN Site on Migration - Upgrading from Visual Basic 6.0: http://msdn.microsoft.com/en-us/vbrun/ms788233.aspx

2) VB6 Interoperability and Migration: http://msdn.microsoft.com/en-us/vbasic/ms789185.aspx

3) Patterns and Practices: UpgradiVB6 to VS 2005: http://msdn.microsoft.com/en-us/library/aa480541.aspx

4) Overview of Changes from VB6 to VB.NET: http://www.4guysfromrolla.com/webtech/053001-1.shtml

5) Another Slideshare.NET migration presentation by one of our own: http://www.slideshare.net/jeffblankenburg/migrating-to-visual-studio-2008-net-framework-35

6) Business Planning Guide for Visual Basic 6.0 Applications http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=4113b928-4575-44a3-b494-020005203161


1) Preparing Your Visual Basic 6.0 Applications for the Upgrade to Visual Basic .NET: http://msdn.microsoft.com/en-us/library/aa260644(VS.60).aspx

2) Webcast: Complete Methodology for Migrating Microsoft Visual Basic 6.0 to Visual Basic .NET (Level 200) - http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?culture=en-US&EventID=1032308930&CountryCode=US


o Safari Online Book "Visual Basic® .NET Developer's Guide to ASP.NET, XML, and ADO.NET ": http://my.safaribooksonline.com/0672321319/ch02lev1sec8

o Free Book - Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET - http://msdn.microsoft.com/en-us/vbrun/ms788236.aspx


Migration Tools:

o VB Upgrade Companion by ArtinSoft: http://migrationguide.artinsoft.com/

o VB Migration Partner Software: http://www.vbmigration.com/

o MSDN Download - Visual Basic 6.0 to Visual Basic .NET Upgrade Assessment Tool: http://www.microsoft.com/downloads/details.aspx?FamilyId=10C491A2-FC67-4509-BC10-60C5C039A272&displaylang=en

o MSDN Download - Upgrading Visual Basic 6.0 Applications to Visual Basic .NET and Visual Basic 2005: http://www.microsoft.com/downloads/details.aspx?FamilyId=7C3FE0A9-CBED-485F-BFD5-847FB68F785D&displaylang=en

o VB 6 Code Advisor: http://msdn.microsoft.com/en-us/vbasic/ms789135.aspx


Unit Testing:

o SimplyVBUnit - http://simplyvbunit.sourceforge.net/

o TinyUnit - http://www.w-p.dds.nl/tinyunit.htm

o VBUnit3 - http://www.vbunit.com/


Other Resources:

o VB6 Resource Center: http://msdn.microsoft.com/en-us/vbrun/default.aspx

o VB Team Blog: http://blogs.msdn.com/vbteam/default.aspx

o VB Team Blog - Migration/Interop: http://blogs.msdn.com/vbteam/archive/tags/VB6_5F00_Migration_2F00_Interop/default.aspx

o Support Statement for Visual Basic 6.0 on Windows®Vista™and Windows®Server 2008: http://msdn.microsoft.com/en-us/vbrun/ms788708.aspx

o Gartner Article "Visual Basic .NET migration costs more than expected, Gartner says": http://searchwindevelopment.techtarget.com/news/article/0,289142,sid8_gci1168001,00.html

o Visual Basic Interop Video Series: http://msdn.microsoft.com/en-us/vbasic/bb466226.aspx#interop

o VB Decompiler: http://www.vb-decompiler.org/index.php?p=help/description