Helping Your VB6 Applications Upgrade

There are a number of things you can do in your VB6 application to make the upgrade easier. This is not a comprehensive list, but it covers some of the most important aspects.

Note that this chapter refers to upgrading VB6 projects—what about VB3, VB4, and VB5 projects? Although the upgrade tool recognizes the format of VB5 and VB6 project types, some VB5 ActiveX references have problems after they are upgraded. For this reason, it's better to upgrade your VB5 applications to VB6—and upgrade the controls to VB6 controls—before upgrading the application to VB .NET. The upgrade tool cannot upgrade projects saved in VB4 and earlier.

Do Not Use Late Binding

As you saw earlier in the chapter, late binding can present some problems because properties and methods cannot be verified during the upgrade process. Avoid late binding whenever possible.

Specify Default Properties

In the previous example, imagine if you had typed the last line of code this way:

oLbl="Hello World"

The Upgrade Wizard has no idea how to handle this. In fact, if you try to upgrade this code, the Upgrade Wizard will include a comment that says it cannot resolve the default property of oLbl.

You should specify the default properties on all your objects. If you don't, the Upgrade Wizard attempts to determine default properties wherever it can. However, default properties on late-bound objects are impossible for the wizard to resolve. You should avoid late binding and also specify any default properties.

Use Zero-Bound Arrays

In VB6, you could create an array with a lower boundary (LBound) of any number you wanted, using this syntax:

Dim MyArray(1 to 5) As Long

VB .NET does not support an LBound of anything but 0, so your code here will end up looking like this in an upgraded project:

'UPGRADE_WARNING: LBound was changed from 1 to 0
Dim MyArray( 5 ) As Integer

The real interesting point here is that the array is not larger by one element; MyArray now has six elements, from zero to five. This could cause problems if you are used to iterating through an array using LBound and UBound, but recall that LBound is not supported in VB .NET.

Examine API Calls

Most API calls work just fine from VB .NET. After all, the underlying operating system is still there and available. Some data types need to be changed because the Long data type in VB .NET is different from the Long data type in VB6. However, the Upgrade Wizard handles most of these for you.

There are some cases in which the Upgrade Wizard can't make the change, however. VB .NET doesn't natively support fixed-length strings, but some APIs expect a structure with a fixed-length string as one of the members. You can use the compatibility layer to get fixed-length strings, but you might have to add a MarshalAs attribute to the fixed-length string.

Also, any API calls that perform thread creation, Windows subclassing, or similar functions can cause errors in VB .NET. Most of these now have VB .NET equivalents, such as .NET's native inheritance and its threading classes.

Form and Control Changes

The OLE Container control is gone. If you have used it, you'll have to code a different way. The Line and Shape controls are gone as well, so lines, squares, and rectangles are replaced by labels. Ovals and circles cannot be upgraded by the wizard, so you'll have to recode those using the GDI+ library.

The Timer control must be disabled to stop it; the interval cannot be set to 0.

The Drag and Drop properties have changed so much from VB6 to VB .NET that they are simply not upgraded by the wizard. You'll have to rewrite that code.

These are not the only changes, of course, but they are some of the most common ones you will see as you upgrade your applications.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.195.225