What's New with the Visual Basic Upgrade Wizard in Visual Basic 2005

 

John Hart
Microsoft Corporation

Updated November 2005

Applies to:
   Microsoft Visual Basic 2005

Summary: Use improvements to the Visual Basic Upgrade Wizard to move Visual Basic 6.0 projects to Visual Basic 2005. (6 printed pages).

Contents

Introduction
Upgrade of New Controls
New Supported Language Features
New Visual Basic 6.0 Project Type
Support for New Visual Basic 2005 Features
Conclusion

Introduction

In Visual Basic 2005, the Upgrade Wizard has added several new features to continue to help you upgrade your Visual Basic 6.0 projects.

The key improvements to the Upgrade Wizard in this version of Visual Basic include the support for upgrading some common Visual Basic 6.0 ActiveX controls, an additional project type, and a few language features that were not previously supported. It also targets some new Visual Basic 2005 features.

Upgrade of New Controls

The Upgrade Wizard in previous versions of Visual Basic .NET did not support upgrading ActiveX controls. Instead, it would create COM Interop wrappers so that you could continue to use the controls as you did from your Visual Basic 6.0 project. The only exceptions to this were the Microsoft Tabbed Dialog control and your own custom user controls.

In Visual Studio 2005 the Upgrade Wizard now upgrades several common ActiveX controls to Windows Forms controls that offer similar functionality.

Several of these controls that are now being upgraded are from the Windows Common Controls Library. This includes the ToolBar, StatusBar, ProgressBar, ListView, ImageList and TreeView controls.

The ToolBar and StatusBar both upgrade to the new ToolStrip and StatusStrip controls in Visual Studio 2005. The ProgressBar, Listview and ImageList controls all also upgrade to similar controls in Visual Studio 2005.

The TreeView control in Visual Studio 2005 does not have a single node collection like the old ActiveX control did. Instead, each Node in the TreeView has its own Nodes collection. In Visual Basic 6.0, you would add a node to the single node collection and specify a relative and what the relationship was. With the new TreeView control, you now simply add child nodes directly to the parent's node collection. This is a much simpler method of adding nodes to the Tree. This does complicate the upgrade, however, because the Upgrade Wizard may not always be able to determine exactly which node collection to which to add the node. It does a good job for the common cases, but because of these differences there may be cases where you will need to modify the logic manually to get the desired node hierarchy. The Upgrade Wizard will identify these cases and issue an Upgrade_Warning to make you aware of this different behavior.

The other ActiveX controls that are now being upgraded to the Windows Forms versions are the RichTextBox, MaskedEdit, WebBrowser, and Common Dialog controls.

The MaskedEdit and the WebBrowser ActiveX controls are both upgraded to the new MaskedTextBox and WebBrowser controls in Visual Studio 2005. Both of these controls have similar functionality, properties, methods, and events to the ActiveX control version.

One thing to note here is that the Upgrade Wizard does not upgrade code that uses the Microsoft HTML Object Library, which you may have used to access the WebBrower control's document. Instead, it will use the same unmanaged library as your Visual Basic 6.0 project did. This would be one area that you may want to enhance, by moving this code to use the new managed HTML Document Object Model after you have your application completely upgraded.

In Visual Basic 6.0 the CommonDialog control contains the functionality for the FileOpen, FileSave, Help, Color, and Font dialogs. The Upgrade Wizard in Visual Studio 2005 now upgrades each of these to the separate common dialog controls. The ActiveX control contained several properties that were shared between two different common dialogs. For example, FileName was a shared property between the FileOpen and FileSave dialogs. The Upgrade Wizard will upgrade these shared properties to properties on the two different common dialogs, if it can determine that each of the Common Dialog controls was used in the Visual Basic 6.0 project. The only common dialog control that is not upgraded is the Help dialog, since there is not an equivalent dialog control in Visual Basic 2005.

In addition to upgrading these ActiveX controls, the Upgrade wizard will also upgrade the Visual Basic 6.0 intrinsic Menu control. This control had previously been upgraded to the Windows Forms MainMenu control by the Upgrade wizard. In Visual Studio 2005 another new control that is being added is the MenuStrip control. Like the other strip controls, this control offers enhanced capability over the standard menu. The Upgrade wizard will now upgrade menus to this new control.

New Supported Language Features

Besides the addition of these features to the Upgrade Wizard, there are also a few other minor enhancements.

In Visual Basic 6.0 you could access a control through the form's control collection by using the controls key. For example,

Form1.Controls("btnOK").Caption = "&OK"

In previous versions of the Upgrade Wizard, it could not map this code to Visual Basic .NET because it was not supported. Now the Upgrade Wizard can upgrade this code easily, because this feature is being added to Visual Basic 2005.

Also new to Visual Basic 2005 is support for changing the key value in the KeyPress event. This adds the same capability that many of you may have used in Visual Basic 6.0 to monitor and restrict the keys that were pressed in a control. For example, it was common to prevent certain characters from being entered in a text box. Take a look at the following Visual Basic 6.0 code example.

Private Sub Text1_KeyPress(KeyAscii As Integer)
   If (KeyAscii < 48) Or (KeyAscii > 57) Then
     KeyAscii = 0
     Beep
   End If
End Sub

When this code was upgraded with previous version of the Upgrade Wizard, it would simply insert an Upgrade_Warning that the KeyChar parameter of the KeyPress event was read-only. Now that this is supported in Visual Basic 2005, the Upgrade Wizard is able to upgrade this code.

New Visual Basic 6.0 Project Type

Microsoft Transaction Server and COM+ Services projects in Visual Basic 6.0 are now upgraded by the Upgrade Wizard to EnterpriseServices projects in Visual Basic 2005.

Support for New Visual Basic 2005 Features

Several of the new items that are now upgraded by Upgrade Wizard have been added to take advantage of new feature in Visual Basic 2005.

The first area that specifically targets these new language features is the upgrade of the Visual Basic 6.0 App Object to matching members of the new My namespace. Specifically the Upgrade Wizard upgrades the following members of the App Object to similar functionality in the My namespace. See this article for more information about the great new features of the My namespace.

App Object Member My.Application Member
CompanyName My.Application.Info.CompanyName
ExeName My.Application.Info.ProductName
FileDescription My.Application.Info.Title
LegalCopyright My.Application.Info.Copyright
LegalTrademarks My.Application.Info.Trademarks
Major My.Application.Info.Version.Major
Minor My.Application.Info.Verison.Minor
Path My.Application.DirectoryPath
ProductName My.Application.Info.ProductName
Revision My.Application.Info.Version.Revision
Title My.Application.Info.Title
LogEvent My.Application.Info.Log.WriteEntry

Windows Forms in Visual Basic 2005 have now added a new FormClosing event, which has a parameter that is very similar to the Unload mode parameter of the Visual Basic 6.0 QueryUnload event so you can now easily determine why the form is closing. Specifically, the upgrade tool is now able to upgrade the UnloadMode parameters to the following FormClosingReasonEventArgs values.

Visual Basic 6.0 Visual Basic 2005
vbAppTaskManager ClosingReason.TaskManagerClosing
vbAppWindows ClosingReason.WindowsShutDown
vbFormControlMenu ClosingReason.UserClosing
vbFormMDIForm ClosingReason. MDIFormClosing
vbFormOwner ClosingReason.FormOwnerClosing
vbFormCode No direct mapping

Visual Basic 2005 is also introducing the concept of Partial Types. See this article for more information. The one key advantage of this is it now allows the Windows Forms designer code to be split out into a separate Designer file that is a Partial type of the Windows Form. The Upgrade Wizard now upgrades Visual Basic 6.0 forms into these two separate files. This helps to reduce the complexity of the code in the Form, because now the only code in the form will be your own.

In previous versions of the Upgrade Wizard it would add a custom DefInstance property to each form and user control, in order to simulate the Visual Basic 6.0 concept of a default instance. The upgraded code that accessed the form by means of its default instance would include a call to this property first, to get the default instance of the form or user control before setting a property or calling one of its public methods. For example, in previous versions of the upgrade wizard the following Visual Basic 6.0 code that resides inside a module,

Form1.Caption = "Hello World" 

would have been upgraded to

Form1.DefInstance.Text = "Hello World" 

Now that the default instance is supported in Visual Basic 2005, the upgraded code looks very much like it did in Visual Basic 6.0.

Form1.Text = "Hello World" 

Also, in Visual Basic 6.0 you could access a form through the global Visual Basic Forms collection. Previous versions of Visual Basic .NET did not have a similar collection. This meant the Upgrade Wizard was not able to upgrade any code that used this collection. Visual Basic 2005 has a new My.Forms collection that is similar to the Visual Basic 6.0 forms collection, so the Upgrade Wizard can now upgrade the code, as well.

Another great new object in the My namespace is the My.Computer object. My.Computer adds several very convenient properties that you will find very useful and simple to use. One of these is My.Computer.Clipboard. This clipboard object has similar functionality to the Visual Basic 6.0 clipboard, which now allows for the Upgrade Wizard to upgrade code that accessed the Visual Basic 6.0 clipboard.

Previously, the Upgrade Wizard would upgrade Visual Basic 6.0 code that accessed resource strings (LoadResString) and data (LoadResData) from resource files, to a function in the Microsoft.VisualBasic.Compatibility library that provided similar functionality. In Visual Basic 2005, we now have the My.Resources object. My.Resources contains properties that represent the items in your resource file. Because these properties offer a great way to access these resources, the Upgrade Wizard will now upgrade code to access the resources directly through My.Resources. To show you just how simple this new code is, look at this next example:

The following Visual Basic 6.0 code,

Msgbox LoadResString(100)

upgraded to the following code in previous versions.

Msgbox(VB6.LoadResource(100))

In Visual Basic 2005, the upgraded code is much cleaner and easier to use and understand.

Msgbox(My.Resources.str100) 

Conclusion

All of these improvements to the Visual Basic Upgrade Wizard are designed to continue to help you move your Visual Basic 6.0 projects to Visual Basic 2005.

© Microsoft Corporation. All rights reserved.