How to Upgrade the Visual Basic 6 Code
Visual Basic 6 (VB6) has a tool, Code Advisor for Visual Basic 6.0, that checks existing code for adherence to best practices. The Advisor alerts you to problems and can save some time in an upgrade to one of the Visual Basic 2005 or other Visual Basic.NET versions. It may not catch all problems but should reduce their number. Within Visual Studio 2005 and Visual Studio 2008, an Upgrade Wizard triggers when you attempt to open a program written in Visual Basic 6.
Instructions
-
-
1
Download and install the free Code Advisor for Visual Basic 6.0 (see the first Resources link). Open Visual Basic 6 and create a new Standard.EXE project to demonstrate the Advisor.
-
2
Double-click on the Textbox control, a small square icon with lower-case letters "ab" in the ToolBox panel on the left of the screen to place a TextBox on the form. Double-click on the CommandButton, a small rectangle under the TextBox control, to add this to the form.
-
-
3
Click on the Text1 box now on the form to view the Properties in the right-hand panel of the screen. The Text property is highlighted. Double-click it to highlight the actual property reading "Text1" and delete it.
-
4
Double-click on the "Command1" button to open the code window. Type the following code and then press "F5" to run it. Do this several times to try out each response when confirmation is asked.
Option Explicit
Private Sub Command1_Click()
Dim yourname, response As String
yourname = InputBox("What is your name?")
Text1.Text = "You said your name was " & yourname
response = MsgBox("Is that correct?", vbYesNoCancel)
If response = vbYes Then
MsgBox ("Fine.")
End
ElseIf response = vbNo Then
Text1.Text = "Sorry, please try again?"
Else: Text1.Text = "Don't give up!"
End If
End Sub -
5
Delete or place an apostrophe in front of the "Option Explicit" line. Change the last word of the line reading "Dim yourname, response As String" to "Double." Press "F5" and note the program still works. Click "Add-Ins" on the top level menu, then "Code Advisor" and select "Add FixIts." The Advisor identifies two problems by adding these lines in the problem position:
'FIXIT: Use Option Explicit to avoid implicitly creating variables of type Variant
'FIXIT: Declare 'yourname' with an early-bound data typeDelete the FIXIT lines. Save the project and exit Visual Basic 6.
-
6
Open a newer version of Visual Basic. Click "File" and "Open Project." Locate the Visual Basic file project you saved in Step 4, which will have a "vbp" extension, and double-click on it. The Upgrade Wizard opens with some preliminary instructions. Click "Next" and choose the type of project, usually an "EXE" version. Click "Next" again, select where to save the new version and agree to a new folder if necessary. Continue to click "Next" until the Wizard begins. When it finishes, all problem areas that must be fixed before the program is compatible will be identified with Upgrade Warnings.
-
1
Tips & Warnings
To upgrade your own code, either use the Code Advisor first or go directly to the Upgrade Wizard in the new Visual Basic software.
Complicated programs in Visual Basic 6 may produce a surprising number of errors needing fixing when migrating to a .NET version.