Migration Mistakes - VB6 to VB.NET Migration
Introduction
There are numerous instances where organizations are running legacy applications on older technologies. They are often faced with the choice of moving to newer, more advanced platforms or continuing with their existing applications. Evolving technologies, at times, force migration upon organizations. As in the case of Visual Basic 6, for which Microsoft has stopped mainstream support in 2005 and paid support comes to an end in 2008. Technology is just one driver for migration. Evolving businesses demand better performance, scalability, security and reach, allowing web-based delivery to customers and web-services and other standards-based integration with vendors and partners. Migrations thus become much more than a cosmetic exercise and require significant planning to ensure their success.
In this white paper, we will specifically address the case of moving from Visual Basic 6 to the Microsoft.NET platform. We examine the pros and cons of a migration exercise and address the issues that come up while migrating. We also cover the strategies and best-practices when doing such a migration.
Visual Basic
Visual Basic is an event driven programming language from Microsoft. It has gained popularity as a rapid-application-development tool for creating graphical user interface (GUI) based applications and prototypes. Currently, the most commonly used version of Visual Basic is VB6. This was first released in mid 1998. Mainstream support for VB6 officially ended on 31, March 2005. However, paid support continues until end March 2008.
Overview of .NET
Microsoft describes .NET as providing “the ability to quickly build, deploy, manage, and use connected, security-enhanced solutions with Web services”.
Essentially .NET is a language-neutral environment for writing programs that can easily and securely interoperate. The components that make up .NET are collectively called the .NET Framework.
The framework can be divided into two logical parts.
- The Common Language Runtime: This is the engine which provides the environment for execution of .NET programs together with the other features like memory management and security.
- A set of reference class libraries
The .NET platform supports over 22+ languages which are all compiled to Intermediate Language (IL) which is processed by the Common Language Runtime. The four languages most commonly used that are supported in the Visual Studio IDE for .NET are C#, VB.NET, C++ & J#.
Choice of .NET language
One of the main concerns while upgrading to new technologies is the re-learning curve for existing developers who modify and maintain the existing system. The best choice for a .NET language would be VB.NET. Although VB.NET, as the name suggests is similar to VB, it is not an extension to the VB family as VB6 was. VB.NET was created as a standard .NET language and is equally powerful as C# and the other .NET languages. It was created with the intention of helping VB developers move to the .NET platform with minimal re-learning.
The advantages of choosing VB.NET over other .NET languages are
- Less steep re-learning curve for current VB6 developers who maintain the product
- Most readable .NET language
- Familiar VB functions like Left$ are retained in VB.NET for the benefit of VB developers.
- Coding is case insensitive like VB
Only .NET language with background compilation. Errors can be viewed at design time without compiling.
Why Move?
Moving to .NET has its benefits. For an application that works perfectly in VB6, a direct migration to the .NET platform will not have any direct impact on performance of the application. However, if after the initial step of directly porting the application, the application is further enhanced both in the look-and-feel and architecturally, with new components from the .NET libraries, significant benefits can be attained on the fronts of extensibility and maintainability of the application.
- Object-Oriented implementation. Unlike VB, VB.NET is an object oriented language. This means that either the architecture can be changed to one using OO concepts, or newer modules can be designed using tools like Rational to speed up the design process
- Web-Services. Core business functionality can easily be exposed as web-services in .NET improving extensibility of the application.
- Move from Windows to the Web. Organizations can make a quick jump from windows to the web using a familiar tool-set. ASP.NET applications can be coded in VB.NET, allowing newer modules to be web-based improving the reach of applications with minimal effort.
- Deployment. Deployment of applications is much improved in .NET compared to VB6. Developers can now use x-copy deployment. No registration of components is needed, eliminating problems like “DLL hell” which VB6 developers experienced.
- More rapid development. .NET provides a suite of controls and other components which have enhanced functionality as compared to those available in VB6. This improves the development time of new modules, and existing components can be replaced with the enhanced ones at a later stage of the migration exercise.
- Cross language capability. Modules written in one .NET language can seamlessly be used and integrated with modules written in another .NET language. This means that new modules can be written in C# by new developers and integrated into the VB.NET application at a later stage.
- Stronger type checking. .NET languages implement stronger type checking. This results in more errors being identified at design time rather than at runtime, thereby speeding up development time and decreasing testing cycles.
- Scalability. .NET gives more inbuilt support for a scalable architecture with existing libraries. Higher concurrent loads can be supported improving overall performance of the application.
- Globalization. Enhanced support from the .NET framework and Visual Studio for globalization makes globalizing windows and web applications a relatively simple task as compared to VB6.
Show Stoppers
There are certain cases when migration to .NET might now be the best way to go. Such cases usually involve applications which largely use very specific features of VB6 which are no longer supported in .NET. As a result, the migration could become quite a messy affair, and re-architecting and implementing such an application from scratch would be a more recommended approach.
A few such known cases are
- Applications extensively using Web Classes, ActiveX Documents, or DHTML will need to be re-written using new technologies as such components are no more supported in VB.NET and cannot be reused.
- Applications built around the Data Environment in VB6 will need to be completely re-architected, as there is no direct equivalent in VB.NET.
The Migration process
Choosing a migration strategy
For a migration of the business or data tiers of an application, there are two possible strategies.
One option is to replace Visual Basic 6 COM components with Visual Basic .NET components. This can either be done horizontally layer-by-layer or vertically module-by-module. Visual Basic .NET ships with an Upgrade Wizard that will upgrade Visual Basic 6 code to Visual Basic .NET. However, for most real life applications, some of the upgrade process will need to be done manually. In the case of the module by module migration, an adapter can be used as an intermediate stage. The adapter which is to be written in .NET, will wrap the existing VB6 COM component to expose it to a .NET client, while the COM component is being migrated to .NET. Finally once the component migration is complete, the adapter can be discarded.
Another option is to expose the Visual Basic COM components as XML Web services. The big advantage to this strategy is that it is very easy to do and one can get a running .NET application very quickly. These Web services can also be exposed across the Internet. This introduces all sorts of interesting possibilities, such as being able to access the application logic from a cell phone or PDA, or to enable business-to-business communication.
Code Preparation
A sizeable chunk of issues resulting from an automated code migration from VB6 to VB.NET, using the upgrade wizard, relate to a small set of issues. Many of these can be more easily fixed before the migration process rather than after. Such issues typically relate to
- Late bound variables and Variants. These can be typed in the VB6 code before migration
- Non-zero bound arrays. These are not supported in VB.NET and can be changed before migration
- Use of Double for storing dates. These can be changed to use the Date object.
Code Migration
The Upgrade wizard packaged with VB.NET is launched when a VB6 application is opened with Visual Studio.NET. This utility attempts to convert existing VB6 code to VB.NET directly. The conversion time is proportional to the size of the application, but is significantly small as compared to the other stages of migration. At the end of the conversion, a report is generated to identify areas where the migration was unsuccessful. TODO Comments are also inserted in the code for portions where the utility could not find a mapping for VB6 components in VB.NET.
Once the automated migration is complete, the migration team will manually need to go through all parts of the code and fix the remaining items which were not successfully migrated due to code ambiguities or incompatibilities.
Post Migration Enhancements
After an ‘as-is’ migration has been completed, and a working version of the application is ready, the next step would be to enhance the application. The first step would be to replace existing components with their newer version available in .NET which offer better functionality (for cases like Windows forms controls).
At the design level, the data handling model from VB6 such as RDO/ADO which is often connected, can be replaced by the disconnected model of ADO.NET.
Visual Basic.NET 2005 also allows users to create Custom Business Objects to store data which are more light-weight when used with web-services.
The overall architecture of the application can be enhanced by using available libraries like the Enterprise Library for .NET which implements best practices for Logging, Exception handling, and abstracts Data Handling increasing the extensibility of the application.
Migration Mistakes
Some of the most common mistakes made during a migration are
- Don’t automate migration and then try to get it to compile. Pre-processing is very important to save time/effort
- Don’t try to migrate the complete application in one go (unless it is very small). Choose a clear strategy: vertical or horizontal to help unit testing. Identify references at this point
- Don’t replace VB components with VB.NET ones during the migration cycle. First reach a working point before adding in new components.
- Don’t use the migration as an exercise to learn VB.NET. Train developers on VB.NET before migration (helps with migration decisions and knowledge on better components in VB.NET which could replace old ones).
- Don’t get overwhelmed by the 1000 over warning and errors resulting from compiling the application in VB.NET the first time. A lot of the warnings will relate to a small set of problems.



