Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
This chapter is from the book

Upgrade Wizard in Visual Studio .NET

Visual Studio .NET is the new development environment for developing Microsoft .NET applications. Because Visual Basic has undergone lots of changes to its syntax and many new features have been added to the language, the Visual Studio .NET IDE contains an upgrade wizard, which helps in upgrading Visual Basic applications to Visual Basic .NET. This section covers details about the upgrade wizard.

Upgrading a Visual Basic 6.0 Project

The upgrade wizard is used to upgrade Visual Basic 6.0 applications into a Visual Basic .NET application. Applications that have been developed using earlier versions of Visual Basic (that is, versions lower than Visual Basic 6.0), have to be upgraded to Visual Basic 6.0 before using the upgrade wizard. The most important thing about this upgrade wizard is that it leaves the original Visual Basic 6.0 project untouched and creates a new Visual Basic .NET project.

If a Visual Basic 6.0 application is opened in Visual Studio .NET, the upgrade wizard is invoked automatically as seen in Figure 3-2. As shown, the upgrade wizard creates a new Visual Basic .NET project, which will be the upgraded version of the Visual Basic application being opened. The wizard will copy each file from the original project into the new project and make the necessary modifications to make it a Visual Basic .NET application.

03fig02.jpgFigure 3-2. First screen when the upgrade wizard is opened in Visual Studio .NET.


On clicking Next, the screen shown in Figure 3-3 is displayed. As shown, the upgrade wizard automatically detects the type of the Visual Basic application to be converted. If the application is a DLL or custom library, the checkbox Generate default interfaces for all public classes is enabled. If this checkbox is not checked, interfaces will be generated only for those classes that have been implemented by other classes in project. If the checkbox is checked, interfaces are generated for all the classes whether they have been implemented by other classes or not.

03fig03.gifFigure 3-3. Selecting the project type for the upgrade wizard.


On clicking Next, we get Figure 3-4. In this screen, the location of the Visual Basic .NET project can be specified. If the directory does not exist, it is created and a Visual Basic .NET project is created in the new directory. On clicking Next, the screen obtained is as shown in Figure 3-5. On clicking Next in the following screen the update process is started as shown in Figure 3-6.

03fig04.gifFigure 3-4. Specifying location for creating the upgraded Visual Basic .NET application.


03fig05.gifFigure 3-5. Ready to Upgrade Screen.


03fig06.gifFigure 3-6. Upgrade Engine is invoked.


Once the upgrade wizard has upgraded the application, the tool prepares an upgrade report that lists all the steps that the wizard has completed and what steps are remaining for the developer to complete the upgrade.

Upgrade Report

When the upgrade tool has finished upgrading the application, it prepares an upgrade report that can be seen in the solution explorer window of Visual Studio .NET. The file name is _UpgradeReport.htm. Double-click the file name so that it will be opened in the Visual Studio .NET browser window. Figure 3-7 shows the upgrade report.

03fig07.jpgFigure 3-7. Upgrade report generated by the upgrade wizard in Visual Studio .NET.


As seen in Figure 3-7, the upgrade report shows the upgrade details. Specifically it shows the new file name (in the Visual Basic .NET project), the old file name (in Visual Basic), and the file type (whether is a form, a class, or so on). It also shows the status of the upgrade (i.e., whether the file was upgraded or whether it had any errors or warnings) and gives the error and warning counts for individual files. Clicking on the + sign next to the file name will give the details of the file, as shown in Figure 3-8. The settings used during the upgrade process are also listed in the upgrade report and a log file is created. Figure 3-8 shows the issues (if any) for a specific file.

03fig08.gifFigure 3-8. Upgrade issues for a specified file.

Now let us look at an example of the upgrade wizard in which there were errors and warnings during the upgrade process. Figure 3-9 shows the screen. As shown, when Visual Basic 6.0 was upgraded, there were a few errors. The report shows the upgrade issues. Specifically the report lists the severity of the error, the location of the error, and the object, and the property on which the error occurred and gives a description of the error.

03fig09.jpgFigure 3-9. Upgrade report showing a list of files with errors and warnings.

COMPILE ERRORS

Compile errors occur when the upgraded code cannot be compiled in Visual Basic .NET because some property or object is not supported in Microsoft .NET Framework. Any issues that fall under compile errors in an upgrade report need to be corrected by the developer; otherwise the application cannot be executed. The upgrade wizard will insert upgrade issues in case of compile errors.

Following are some of the cases that cause compilation errors during the upgrade:

  • The Visual Basic 6.0 application uses ListIndex property of ListBox or ComboBox control.

  • The Visual Basic 6.0 application uses DrawStyle property of PictureBox control.

  • Functions like VarPtr, StrPtr, ObjPtr, MidB, and ChrB and statements like GoSub have been used in the Visual Basic 6.0 application.

  • The Visual Basic 6.0 application is trying to set a read-only property of particular control.

DESIGN ERRORS

When design errors occur, the upgraded code can be compiled and executed in Visual Basic .NET. This error indicates that a property that can be set at design time in Visual Basic 6.0 cannot be set then in Visual Basic .NET. Design errors generally apply to forms and controls. Some causes for design errors are as follows:

  • A particular property of one control has a new behavior in Visual Basic .NET. Following are some of the cases that cause these errors:

    • TextBox.TextLength property

    • Form.Picture property

    • Form.Unload event

    • ComboBox.Change event

  • Raster fonts are used on the Visual Basic form.

  • A particular property or method of Visual Basic 6.0 has been removed in Visual Basic .NET

Warnings

The upgraded code can be compiled and executed in Visual Basic .NET. The upgrade wizard issues a warning when some property that could be set in Visual Basic exhibits a changed behavior in Visual Basic .NET. Any warnings should be examined to make sure that they do not affect application behavior. Following are some of the cases when the upgrade wizard issues warnings:

  • If arrays have been declared with New keyword.

  • If an array doesn't have a zero lower bound.

  • If Visual Basic application has used Null or IsNull because Null is not supported in Visual Basic .NET.

  • In Visual Basic .NET some of the properties enumerators of Visual Basic 6.0 have changed. Therefore, an upgrade wizard shows a warning that the value for particular property could not be resolved.

There are instances when no error is listed in the upgrade report, but the application fails to execute in the Microsoft .NET environment. However, such cases are very infrequent.

As Figure 3-9 indicates, the descriptions of the errors and warning are actually hyperlinks, which provide links to the specified materials in Microsoft .NET documentation. For example, clicking on the third description in the figure will lead to the screen shown in Figure 3-10. This screen gives an indication of why there was an error in upgrading the Visual Basic application to Visual Basic .NET. It also gives a pointer and a detailed explanation to the developer on how to solve the error.

03fig10.jpgFigure 3-10. MSDN documentation for the specified error/warning.

In addition to the upgrade report, the wizard also puts comments in the upgraded code to indicate that there were issues. The following code snippet shows a Visual Basic .NET code that was generated by the upgrade wizard:

   Private Sub Form1_Click(ByVal eventSender As_ 

      System.Object, ByVal eventArgs As System.EventArgs)_ 

         Handles MyBase.Click 

   'UPGRADE_ISSUE: PictureBox property Picture1.FillColor 
       was not upgraded. Click for more: 'ms-help://MS.VSCC 
          /commoner/redir/redirect.htm?keyword="vbup2064"' 

      Picture1.FillColor = System.Drawing.ColorTranslator._ 
         ToOle (System.Drawing.Color.Red) 

'UPGRADE_ISSUE: PictureBox property Picture1.FillStyle 
        was not upgraded. Click for more: 'ms-help: // 
           MS.VSCC / commoner/redir/ redirect.htm?keyword 
              ="vbup2064"' 
      Picture1.FillStyle = 0 
'UPGRADE_ISSUE: PictureBox method Picture1.Circle was 
        not upgraded. Click for more: 'ms-help://MS.VSCC/ 
           commoner/redir/redirect.htm?keyword="vbup2064"' 
  Picture1.Circle (VB6.PixelsToTwipsX(Picture1.Width)/_ 
         2, VB6.PixelsToTwipsY(Picture1.Height) / 2),_ 
            VB6.PixelsToTwipsY(Picture1.Height) / 2 
End Sub 

In this code, the upgrade wizard has marked lines of code with an upgrade issue warning. The wizard also provides a link to MSDN documentation on more specifics of the upgrade issues.

Performance of the Upgrade Wizard

For small projects, the upgrade wizard works very quickly. For Visual Basic 6.0 projects that use COM and ActiveX components, the upgrade wizard updates a copy of the main Visual Basic 6.0 project. The original copy of the project is left unchanged. In addition, it creates a COM interoperability layer to enable the new Visual Basic .NET application to interact with the original COM components.

This means that when you upgrade Visual Basic 6.0 projects, all the referenced COM and ActiveX controls are not upgraded automatically. Instead, it uses the feature of interoperability mechanism provided by the Microsoft .NET Framework to interact with these COM and ActiveX components.

The pre-migration recommendations provided in this book have been suggested to improve the performance of upgrade wizard. The Visual Basic 6.0 code needs to can be changed as per pre-migration recommendations before upgrading it using the upgrade wizard.

  • + Share This
  • 🔖 Save To Your Account