When executing a VB6 to .NET migration project, you should apply tools that automate as much of the conversion as possible. The most accessible of those tools is the Visual Basic Upgrade Wizard, part of the Visual Studio.NET IDE and created by Mobilize.NET for Microsoft. To ensure a smooth, efficient migration, it is helpful to understand the upgrade wizard supported features in relation to the Visual Basic 6.0 application. From declarations and properties to modules and interfaces, Chapter 6 describes how the tool manages to upgrade from VB6 to .NET. Also, learn about the characteristics of the resulting code, the VB 6.0 upgrade issues that may occur and the tasks you will need to perform after the upgrade wizard had done its job.
The Visual Basic Upgrade Wizard, created by Mobilize.NET for Microsoft, is an automated source code upgrade tool that upgrades a project written in Visual Basic 6.0 to a series of files written in Visual Basic .NET. It takes into account the different aspects of software creation and transformation, including program organization, statements, expressions, symbols, data types, literal values and variables, creating a new project, copying each file from the original project into the new one, and modifying the files as necessary. Finally, it generates a report detailing what was done and what you need to do to finish the upgrade.
The upgrade tool is available in two forms: the upgrade wizard that is integrated into the Visual Studio .NET development environment and a command-line tool that is available with the .NET Framework.
Visual Basic 6.0 | Visual Basic .NET |
Standard EXE | Windows Application |
ActiveX DLL | Class Library |
ActiveX EXE | Class Library |
ActiveX Control | Windows Control Library |
ActiveX Document | No direct Equivalent Visual Basic .NET can interoperate with ActiveX Documents |
DHTML Application | No direct equivalent. Use ASP .NET Web Application |
IIS Application (WebClass) | No direct equivalent. Use ASP .NET Web Application |
Yes, when the upgrade wizard upgrades a project to Visual Basic .NET, it inspects the code for references to other files in the project, and to any external libraries, components, COM objects, and files.
No, but there’s an enhanced version (or enterprise edition) of the upgrade wizard called the Visual Basic Upgrade Companion, developed and sold by Mobilize.NET, the same company that built the Upgrade Wizard for Microsoft. It can parse database schema definition files to obtain additional information about field data types and produce improved Visual Basic .NET code.
This and other enhancements can help you further shorten your upgrade process by automating more of it. It can even be customized to extend its functionality, according to the characteristics of the application to be migrated.
When the upgrade wizard upgrades your project, it generates a report that can be used as a guide for the manual changes that your project requires afterwards. It details the results of the upgrade process, as well as a list of issues uncovered during the upgrade that you need to address before your project can be compiled. It’s in in HTML format and you can view it within the Visual Studio .NET development environment, by double-clicking the _UpgradeReport.htm file in Solution Explorer, or in an external Web browser, by choosing Browse With from the File menu.
The top portion of the report contains a list of global issues followed by a listing for each file that was upgraded. By expanding the section for each file, you can view a detailed list of issues that will need to be addressed, along with the location of the code that must be fixed and a description of the issue. The last portion of the report contains general information about the upgrade, including the settings that were used during the upgrade and the location of the new project files.
In addition to the report, the upgrade wizard inserts comments into your upgraded code alerting you to statements that will need to be changed. These comments are displayed as TO DO tasks in the new Visual Studio .NET Task List window, so you can easily see what changes are required. Double-clicking a task in the task list will immediately take you to the relevant line of code. Each task and item in the upgrade report is associated with an online Help topic that gives further information on why the code needs to be changed, and guidance on what you need to do to resolve the issue.
The upgrade wizard automatically upgrades variable declarations to their equivalent.NET Framework types, following the Visual Basic .NET structure and
taking into account the Visual Basic 6.0 declaration guidelines. For example, in Visual Basic .NET, variables must be declared explicitly, and there is no Variant data type, so in those cases the upgrade wizard changes the code to declare using the Object data type, which is the .NET Framework’s closest equivalent to Variant.
Parameters can be passed to a procedure or function in one of two ways: by reference (ByRef) or by value (ByVal). When a parameter is passed to a subprocedure by reference, changes made to the parameter’s value affect the actual variable or object passed by the calling procedure. When a parameter is passed by value, the subprocedure uses a copy of the original variable or object, and any changes the subprocedure makes to it do not affect the original.
By default, Visual Basic 6.0 uses the ByRef method when the parameter’s data type is an intrinsic one such as Integer, Long, Boolean, String, and so on. When a parameter uses a non-intrinsic data type, Visual Basic 6.0 passes it by value by default.
By comparison, Visual Basic .NET passes all parameters by value unless otherwise specified. If a parameter keyword is specified in the signature a Visual Basic 6.0 routine, the upgrade wizard will generate the Visual Basic .NET routine accordingly. If ByVal or ByRef are not specified for a parameter in a Visual Basic 6.0 routine, the upgrade wizard will specify ByRef for the parameter.
In Visual Basic 6.0, properties are defined using the Property Get, Property Let, and Property Set statements. Visual Basic .NET replaces these statements with a new property declaration syntax that uses Get and Set accessors to provide access to the property.
Events in Visual Basic .NET are built on top of delegates, so they are handled very differently from events in Visual Basic 6.0.
The upgrade wizard automatically handles the details surrounding events by generating signatures for the methods according to the rules of the .NET Framework, and by adding the necessary Visual Basic keywords to comply with the Visual Basic .NET events infrastructure.
Some of the Visual Basic .NET control structures are slightly different from the control structures in Visual Basic 6.0. For example, the Wend keyword, that ends
While loops in Visual Basic 6.0, is replaced by End While in Visual Basic .NET. The upgrade wizard automatically upgrades Visual Basic 6.0 flow statements and preserves their functionality.
Yes. In Visual Studio 6.0, module and class files have distinct file name extensions (.bas for modules, .cls for classes), and are organized in specific folders within the Project folder. In Visual Basic .NET, modules and class files both have the same file name extension, .vb, and are distinguished from one another by the structure within each file.
The upgrade wizard automatically handles file name upgrades. For each element, the upgrade wizard will compose a name based on a specific structure.
In VB 6.0, common classes can be treated as interfaces. The upgrade wizard generates both a class and an interface to replicate this behavior.
In Visual Basic 6.0, WebClass projects (also known as IIS application projects) are used to create Web applications based on Active Server Pages (ASP) technology. In Visual Basic .NET, ASP.NET Web application projects are used to create Web applications based on the newer ASP.NET technology.
When upgrading WebClass projects with the upgrade wizard, there are some issues that you should consider.
There are two prerequisites for upgrading a WebClass project:
Both Visual Basic 6.0 and Visual Basic .NET support late-bound objects. However, during the upgrade process, late-bound objects can introduce problems when default properties are resolved, or in cases where the underlying object model has changed and properties, methods, and events need to be upgraded.
There are two ways to correctly upgrade late-bound objects:
You could also use the Visual Basic Upgrade Companion as an alternative solution to the late-bound variable problem. Its Type Inference feature deduces the most appropriate data types for variables, parameters, and returns values, and avoids using generic data types such as Object. When the companion tool encounters an Object variable, it declares the variable using the appropriate type so that you do not have to make manual modifications.
The upgrade wizard upgrades type casting statements using the appropriate type
restrictions. For example, this Visual Basic 6.0 code converts a 16-bit integer to a
string, and then back to an integer.
Enumerations, or enums, are a special type of value type. An enum has a name and a set of fields that define values for a primitive data type.
The upgrade wizard automatically upgrades enumerated types and their references to the format used by Visual Basic .NET.
In Visual Basic 6.0, you can use user-defined types (UDTs) to create groups of data items of different types. In Visual Basic .NET, UDTs are called structures. A structure associates one or more members with each other and with the structure itself. When you declare a structure, it becomes a composite data type, and you can declare variables of that type.
The Visual Basic 6.0 native libraries — which provide much of the language’s core functionality — have been replaced by the .NET Framework itself. The .NET Framework provides the .NET languages with core functionality through the System namespace and other namespaces. The upgrade wizard automatically replaces calls to the Visual Basic 6.0 native libraries with calls to the equivalent .NET Framework objects and classes.
The upgrade wizard converts VB 6.0 forms (files with the file name extension .frm) to Windows Forms, the .NET Framework’s form development system, which uses classes in the System.Windows.Forms.Form namespace. Upgraded form files are saved with the file name extension .vb, like other Visual Basic .NET code files. Each Visual Basic 6.0 form’s properties, methods, and events (PME) is upgraded to an equivalent System.Windows.Forms.Form PMEs.
As you know, Visual Basic 6.0 supports resource files that have the file name extension .res. Each Visual Basic 6.0 project can have one resource file. Resource files in Visual Basic .NET have the file name extension .resx. They consist of XML entries that specify objects and strings inside XML tags.
When you use the upgrade wizard to upgrade a Visual Basic 6.0 project that has an associated resource file, the wizard automatically upgrades the Visual Basic 6.0 .res file to a Visual Basic .NET .resx file.
Visual Basic 6.0 form binary files (files with the file name extension .frx) contain necessary resources for the main program form, such as images and icons. In Visual Basic .NET, binary resources are encoded into .resx files. Forms can retrieve resources automatically from associated resource files. The upgrade wizard upgrades .frx files to .resx files associated with a Form class.
In Visual Basic 6.0, the ScaleMode property can be used to change the coordinate system for a form or PictureBox control from the default scale of twips. Visual Basic .NET does not support multiple coordinate systems; all measurements must be expressed in pixels. When you upgrade a project to Visual Basic .NET, the upgrade wizard automatically converts the design-time coordinates of visual components from twips to pixels. Code that sets the ScaleMode property at run time will cause a compilation error and must be manually modified.
The upgrade wizard also uses upgraded methods in the Microsoft.VisualBasic.Compatibility.VB6 namespace to upgrade run-time modifications of a control’s position.
The .NET Framework provides equivalents for most of the Visual Basic 6.0 standard user interface controls; however, some Visual Basic 6.0 controls have no .NET equivalents, and others have been renamed.
A control array is a group of controls that share the same name, type, and event procedures. Elements of the same control array have their own property settings. The upgrade wizard relies on functions and objects in the Microsoft.VisualBasic.Compatibility.VB6 namespace to upgrade control arrays.
Visual Basic 6.0 data environment modules have the file name extension .dsr. They contain information used to create ADO connections and commands to access data, which are upgraded to VB .NET using classes in the Microsoft.VisualBasic.Compatibility.VB6.BaseDataEnvironment, ADODB.Connection and ADODB.Command namespaces, respectively. The upgrade wizard converts Active Designer (.dsr) files to .vb files. Each .vb file contains a class that inherits from Microsoft.VisualBasic.Compatibility.VB6.BaseDataEnvironment.
The upgrade wizard generates two types of wrappers around each component:
The upgrade wizard adds these wrappers to the project as DLLs, migrates references to the ActiveX component and its properties, methods, and events, and adds any design-time initializations of the component’s properties to the InitializeComponent method.
VB 6.0 uses user controls that are also known as ActiveX Control projects, to create ActiveX controls. After user controls are compiled, they can be hosted in any container that supports ActiveX, including Visual Basic 6.0 forms and Internet Explorer.
In Visual Basic .NET, Windows Class Library projects are used to create reusable classes and components that can be shared with other projects and hosted in Windows Forms applications. The Windows Class Library template replaces the ActiveX DLL project template in Visual Basic 6.0.
The upgrade wizard transforms Visual Basic 6.0 user controls to Windows Class
Libraries. If the entire project is an ActiveX DLL, the upgrade is automatic. If the project is a standard Visual Basic project that contains User Controls, the upgrade wizard will not create a separate project for these components. After upgrading the application, you should manually create a Class Library project and move the components from the upgraded application to the new project.
8834 N Capital of Texas Hwy, Ste 302
Austin, TX 78759
Call us: +1 (425) 609-8458
info@wearegap.com