Upgrading Visual Basic 6.0 Code with the Upgrade Visual Basic 6 Code Dialog Box
The Upgrade Visual Basic 6 Code dialog box is a tool that converts Visual Basic 6.0 code to equivalent Visual Basic .NET code. Unlike the Visual Basic Upgrade Wizard, which upgrades an entire application, the Upgrade Visual Basic 6 Code dialog box is available at design time to convert small amounts of code as you are developing your Visual Basic .NET application.
The Upgrade Visual Basic 6 Code dialog box is useful in two ways:
- You can make use of existing Visual Basic 6.0 code by pasting it into the tool.
- You can type in code using Visual Basic 6.0 syntax in order to learn the Visual Basic .NET equivalent.
After running the tool, Visual Basic .NET code is inserted into the Code Editor at the current cursor location. If there are any problems with the conversion, comments are inserted with clickable links to help topics that explain the problem and any possible workarounds.
To upgrade Visual Basic 6.0 code
- In the Code Editor, move your cursor where you want to insert code.
- On the Tools menu, choose Upgrade Visual Basic 6 Code.
The Visual Basic 6.0 Code Upgrade dialog box will be displayed.
- In the Visual Basic 6.0 Code Upgrade dialog box, paste in existing Visual Basic 6.0 code, or enter code using Visual Basic 6.0 syntax.
- If your code references a COM component, select the References tab and click Add Reference, then select the reference in the Add Reference dialog box.
- Click Upgrade to convert the code and insert it into the Visual Basic .NET Code Editor.
Any COM references will be added to the References node for your project in Solution Explorer, and a project-level Imports statement will be added for the Microsoft.VisualBasic.Compatibility namespace.
Tips for Using the Upgrade Visual Basic 6 Code Dialog Box
The Upgrade Visual Basic 6 Code dialog box has some limitations; not all code can be successfully converted. The following tips can help you to get the most out of the tool.
- Not all Visual Basic 6.0 code is compatible with Visual Basic .NET. For more information about the limitations, see Things to Consider Before Upgrading.
- How your Visual Basic 6.0 code is written can have an effect on how it is upgraded. There are a number of recommendations that you can follow that will make your code easier to upgrade. For more information, see Language Recommendations for Upgrading.
- If the code does not run successfully in Visual Basic 6.0, it will not run in Visual Basic .NET. When pasting code from a Visual Basic 6.0 project, you should first test the code before attempting to upgrade.
- Event signatures in Visual Basic .NET are different than their Visual Basic 6.0 counterparts. When entering code for form or control event procedures, it is best to first add the procedure declaration in Visual Basic .NET and then upgrade only the body of the procedure.
- The Upgrade Visual Basic 6 Code dialog box is designed to upgrade small sections of code. It relies on the code typed into the dialog box to determine context for the upgrade.
For example, the statement
L.Caption = "MyCaption"would not be translated because the tool does not know what type "L" is, so it cannot resolve the property "Caption". Inserting a declaration for "L" (Dim L As Label) prior to the statement would result in a proper upgrade.
- Entering invalid Visual Basic 6.0 syntax can result in an "Untranslated statement in WrapperSub" error. If you see this error, inspect your code to make sure the syntax is correct.
- For best performance, upgrade code in modules rather than in Form modules. If you need to upgrade a form, use the Upgrade Wizard.