Upgrading Visual Basic 6.0 Applications with Visual Basic .NET 2003
Upgrading Visual Basic 6.0 applications to .NET involves a good bit of automation thanks to an upgrade wizard. Even so, there are certain issues involved, and some applications might be better off left in VB 6. This article will take you step by step through an upgrade, explain the core issues, and help you decide which of your applications to upgrade.
Visual Basic 6.0 is a lightweight, robust and powerful development environment built for developers. With the release of Visual Basic .NET, developers gradually shifted their attention to .NET and hence there was a need to upgrade existing Visual Basic 6.0 applications. It is nearly impossible to convert an existing Visual Basic 6.0 application to Visual Basic .NET from scratch. It will involve a substantial amount of time and investment.
For the purpose of this article, I will make use of a free open source application which is named MetaCoder. I had initially developed this little application using Visual Basic 6.0. It will enable you to generate Meta codes for your web pages. I am currently working to port this application into .NET, and I will show you how to do this using Visual Basic .NET 2003 in a step-by-step manner. You can download MetaCoder right here.
In this article, I will examine the steps required to upgrade an existing Visual Basic 6.0 project using Visual Basic .NET 2003, and also provide some explanation of additional issues which you will commonly face during an upgrade. Visual Basic .NET ships with a cool tool called upgrade wizard. This wizard will perform all the required tasks associated with an application upgrade.
Launch Visual Studio .NET 2003 (Start | All Programs | Microsoft Visual Studio .NET 2003 | Microsoft Visual Studio .NET 2003) and open the Visual Basic 6.0 project (File | Open | Project). Visual Basic .NET will automatically launch the upgrade wizard as shown below.
Figure 1
Click Next to continue, and specify the project type and the location where you would like to save the upgraded project (see Figure 2 and 3).
Figure 2
Figure 3
Click the Next button to begin the upgrade process. Figure 4 shows a screenshot of the process.
Figure 4
The wizard automatically exits after the upgrade process has been finished. The next step is to locate the folder where you saved the upgraded project and open the Visual Basic .NET project file for further investigation.
An important point to note is that you should successfully compile and execute the Visual Basic 6.0 project before beginning the upgrade process. This will ensure a smooth and trouble free upgrade.
The Visual Basic .NET upgrade wizard creates an HTML file which contains a detailed report about the upgraded application. This file can be found inside the folder in which you placed the upgraded application, and will point out the parts which are not upgraded. I will explain more about this report in the next section of this article.
If you inspect the folder in which you placed the upgraded application, you should be able to find a file with the name _UpgradeReport.htm. A screenshot of this file is given below for your reference.
Figure 5
It will list the project file names as well as their status. The file will also point out any errors or warnings (if any). The file includes a section called Upgrade Settings. This section will list among other things the name of the log file, path of the application, and so on.
You should investigate any comments listed by the upgrade wizard inside the project files. The wizard will generally add comments if that part of the application cannot be upgraded. These comments also show up in the Visual Studio .NET TaskList. There are four different kinds of comments which the upgrade wizard can add to your code. They are:
UPGRADE_ISSUE
UPGRADE_TODO
UPGRADE_WARNING
UPGRADE_NOTE
Let us now examine each of these in detail.
UPGRADE_ISSUE
These comments mark any lines of code that will prevent your code from compiling properly. You should correct these errors before compiling the project. For this purpose, you may have to go through all the files and inspect their code.
UPGRADE_TODO
These comments indicate those portions of code that will compile but will cause a runtime error. Runtime errors are called exceptions. You should fix these errors before compiling the project.
UPGRADE_WARNING
These comments also indicate those portions of code that will compile but may cause a runtime error. As explained above, runtime errors are called exceptions. You should go through these warning messages (if any) and rectify them before executing the project.
UPGRADE_NOTE
These comments mark code that will surely compile and run, but indicate any changes between the codes that could have potential effects. I would strongly suggest you go through these notes and make any modifications to prevent any problems in the future.
One of the points to note with regard to comments is that they will include a hyperlink to the relevant help topic that is associated with the issue.
Visual Basic .NET will automatically list all the upgrade comments on its TaskList as shown in the figure given below.
Figure 6
The above figure shows the entries included on a single Windows Form. Double clicking an entry will take you directly to the corresponding code listing. You can then modify the code after going through the comments listed there.
As explained above, you must resolve all issues to ensure that your upgraded application runs correctly. The TaskList includes UPGRADE_ISSUES, UPGRADE_TODO and UPGRADE_WARNING comments. You need to go through each one of the entries and resolve them appropriately.
Before upgrading a Visual Basic 6.0 project to its .NET counterpart, you should first assess the usefulness of the same. It is better not to upgrade complicated projects, as you may be required to do more work to address all the issues.
The Visual Basic .NET upgrade wizard does not upgrade all parts of a Visual Basic 6.0 application. You will have to manually update the application if certain features of Visual Basic 6.0 have no equivalent to Visual Basic .NET. Visual Basic .NET does not support the following listed features of Visual Basic 6.0:
OLE Control:
This control is popularly called as OLE container control. VB.NET does not contain this control. However, you can make use of WebBrowser control as an alternative.
Dynamic Data Exchange (DDE):
You can use the SendMessage API instead of DDE methods.
DAO and RDO data binding:
DAO stands for Data Access Object and RDO stands for Remote Data Object. They are accessed through code with the help of Data control in Visual Basic 6.0. Visual Basic .NET does not support these two data binding concepts. You should either use Active Data Objects (ADO) before upgrading, or convert the entire code to ADO.NET after completing the upgrade.
Visual Basic 5.0 Controls:
Visual Basic 6 ships with lot of VB 5 controls such as Microsoft Windows Common Controls and the data bound grid control. VB.NET doesn’t support these controls. It is better to leave them without upgrading or use the equivalent .NET controls such as DataGrid.
DHTML Applications:
You can develop DHTML applications using Visual Basic 6.0. These applications cannot be upgraded by Visual Basic .NET. It is better to leave these applications in their VB 6.0 versions.
ActiveX Documents:
The VB.NET upgrade wizard cannot upgrade ActiveX documents developed using Visual Basic 6.0.
Property pages:
VB.NET does not support property pages, because you can easily make use of the Windows Forms property browser.
User controls:
You can use User controls developed using Visual Basic 6.0 in your Visual Basic .NET applications, but .NET does not provide design-time support. Hence, you can make modifications to User controls only by using Visual Basic 6.0
WebClass Applications:
These applications will be upgraded to ASP.NET with an upgrade warning. You should review those warnings before deploying your project. You should further note that WebClasses interoperate with VB.NET Web Forms in a flexible manner.
Summary
You have now attained the knowledge to upgrade a Visual Basic 6.0 application to .NET. This article also examined some of the core issues associated with the upgrade. I hope this article helped you to decide whether to upgrade your existing Visual Basic 6 applications into Visual Basic .NET 2003.