How to use the Visual Basic Upgrade Wizard (317885)



The information in this article applies to:

  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft .NET Framework 1.1

This article was previously published under Q317885

SUMMARY

This step-by-step article explains how to create a simple Visual Basic 6.0 application, and then upgrade the application to Visual Basic .NET or Visual Basic 2005 by using the Visual Basic Upgrade Wizard in Visual Studio .NET or in Visual Studio 2005.

Note The Visual Basic .NET Upgrade Wizard is included in Visual Studio .NET Professional.

Note The Visual Basic 2005 Upgrade Wizard has been enhanced from earlier versions of Visual Basic. For more information, visit the following Microsoft Developer Network (MSDN) Web site: back to the top

Requirements

The following items describe the recommended hardware, software, network infrastructure, skills, knowledge, and service packs you will need:
  • Microsoft Windows 2000 Professional (or Server), or Microsoft Windows XP Professional (or Server) with the .NET Framework installed
  • Microsoft Visual Basic 6.0
  • Microsoft SQL Server 7.0 or later with the Northwind database, the appropriate permissions and UserID and Password values
Prior knowledge required:
  • General knowledge of how to create applications by using Visual Basic 6.0
back to the top

Use the Visual Basic Upgrade Wizard

The following steps show you how to create a simple Visual Basic 6.0 application, and then upgrade the application to Visual Basic .NET or Visual Basic 2005 by using the Visual Basic Upgrade Wizard in Visual Studio .NET or in Visual Studio 2005:
  1. On the Start menu, point to Programs, point to Microsoft Visual Studio 6.0, and then click Microsoft Visual Basic 6.0.
  2. In the New Project dialog box, click Standard EXE, and then click Open.
  3. The first form in this application uses ADO to retrieve a recordset, and then displays the recordset in a Microsoft Hierarchical FlexGrid Control. In the Name field of the Properties dialog box for Form1, type frmADO.
  4. If the Toolbox is not open, on the View menu, click Toolbox.
  5. From the Toolbox, place an MSHFlexGrid on the form so that it fills most of the form. Leave enough space at the bottom of the form to place a button.

    NOTE: If you do not see the MSHFlexGrid icon in the Toolbox, add it to the Toolbox. Right-click the Toolbox, and then click Components. In the Components dialog box, click to select Microsoft Hierarchical FlexGrid Control 6.0 (OLEDB) from the list of available components, and then click OK.
  6. From the Toolbox, place a CommandButton on the form below the MSHFlexGrid. In the Caption field of the Properties dialog box, type OK.
  7. Right-click mADO, and then click View Code. Add the following code, which creates a database connection and returns a recordset that contains all of the data from the Products table of the Northwind database.

    NOTE: In the following sample code, you must change user id=<username> and password=<strong password> to the correct values. Make sure that the user ID has the appropriate permissions to perform this operation on the database.
    Private Sub Command1_Click()
        Unload Me
    End Sub
    
    Private Sub Form_Load()
        Dim cn As Connection
        Set cn = New Connection
        cn.ConnectionString = "Provider=sqloledb;Data Source=localhost;database=northwind;user id=<username>;password=<strong password>"
        cn.Open
        
        Dim rs As Recordset
        Set rs = New Recordset
        rs.CursorLocation = adUseClient
        rs.Open "select * from products", cn
        
        Set MSHFlexGrid1.DataSource = rs
    End Sub
    					
  8. Press CTRL+S to save the form. On the File menu, click Save As. In the Save As dialog box, click Save.
  9. In the Project Explorer, right-click Project1, click Add, and then click Form. Click Open.
  10. In the Name field of the Properties dialog box, type frmClipboard.
  11. From the Toolbox, place a Textbox on the form. In the Text field, type The quick brown fox jumped over the lazy dog.
  12. Place a CommandButton below the Textbox. In the Caption field of the Properties dialog box, type Copy.
  13. Place a second CommandButton on the form. In the Caption field of the Properties dialog box, type Paste.
  14. Right-click frmClipboard, and then click View Code. Paste the following code for the CommandButton click events. This code uses the Clipboard object to GET and paste the text:
    Private Sub Command1_Click()
        Clipboard.SetText Text1.SelText
    End Sub
    
    Private Sub Command2_Click()
        Text1.SelText = Clipboard.GetText
    End Sub
    					
  15. Press CTRL+S to save the form.
  16. The last form you need is the main form of the application. In the Project Explorer, right-click Project1, click Add, click Form, and then click Open.
  17. In the Name field of the Properties dialog box, type frmMain.
  18. From the Toolbox, place a CommandButton on the frmMain form. In the Caption field of the Properties dialog box, type ADO.
  19. Place a second CommandButton on the form. In the Caption field of the Properties dialog box, type Clipboard.
  20. Right-click frmMain, and then click View Code. Paste the following code for the CommandButton click events, to show the other two forms:
    Private Sub Command1_Click()
        frmADO.Show
    End Sub
    
    Private Sub Command2_Click()
        frmClipboard.Show
    End Sub
    					
  21. Press CTRL+S to save the form.
  22. In the Solution Explorer, right-click Project1, and then click Project1 Properties. In the Startup Object field, click frmMain, and then click OK.
  23. To add a reference to the ADO component, on the Project menu, click References. In the list of available references, click to select Microsoft ActiveX Data Object Library (any version 2.0 or later will do). Click OK.
  24. To compile the project, on the File menu, click Make Project1.exe. In the Make Project dialog box, click OK (accept the default file name).
  25. Press F5 to run the application in debug mode.

    NOTE: You do not need to verify that the legacy Visual Basic application runs without any problems before you upgrade.
  26. Close the Visual Basic development environment. At the prompt to save changes to the project, click Yes. Use the default name and save the project.
  27. On the Start menu, point to Programs, point to Microsoft Visual Studio .NET, and then click Microsoft Visual Studio .NET.
  28. On the Start Page, click Open Project. Locate the folder that contains the Visual Basic 6.0 project file that you just created (typically C:\Program Files\Microsoft Visual Studio\VB98). Click Project1.vdp, and then click Open.
  29. Visual Studio .NET detects that this is a legacy Visual Basic project and starts the Visual Basic Upgrade Wizard. The wizard displays a description of each step as you proceed through the steps, in the following sequence:
    • Create a new project into which your existing project is upgraded.
    • Copy form files and class files into the new project.
    • Provide an upgrade report that lists the components of the project that upgraded successfully and the components that did not upgrade succesfully.

  30. Click Next through each of the steps until the upgrade process begins. The upgrade takes approximately 30-60 seconds to complete.
  31. In the Solution Explorer, double-click _UpgradeReport.htm. This report displays the results of the upgrade. Note that all of the forms except frmClipboard upgraded without any issues.
  32. Expand frmClipboard.vb to view the issues. Clipboard.SetText and GetText did not upgrade properly. Click the links in Description to view how to correct the issues.
  33. In the Solution Explorer, note that all of the forms kept their original names, but the file extension is changed from .frm to .vb.
  34. Expand References. Note that references to all of the components that are required to use legacy Visual Basic and ADO components were added automatically.
  35. Right-click any of the forms, and then click View Code. Expand the Upgrade Support region. This area displays how Visual Studio .NET or Visual Studio 2005 configured various properties and variables to support the upgraded code.
  36. In the Solution Explorer, right-click frmClipboard.vb, and then click View Code. Note that there are comments placed before the lines that did not upgrade.
  37. Change the Command1_Click and Command2_Click events to the following:
    Private Sub Command1_Click(ByVal eventSender As System.Object, _
        ByVal eventArgs As System.EventArgs) Handles Command1.Click
            Clipboard.SetDataObject(Text1.Text)
        End Sub
    
        Private Sub Command2_Click(ByVal eventSender As System.Object, _
        ByVal eventArgs As System.EventArgs) Handles Command2.Click
            Text1.SelectedText = _
                Clipboard.GetDataObject().GetData(GetType(System.String))
        End Sub
    					
back to the top

Complete Code Listings

Complete Code Listing (frmADO.frm)

Private Sub Command1_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    Dim cn As Connection
    Set cn = New Connection
    cn.ConnectionString = "Provider=sqloledb;Data Source=localhost;database=northwind;user id=<username>;password=<strong password>"
    cn.Open
    
    Dim rs As Recordset
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open "select * from products", cn
    
    Set MSHFlexGrid1.DataSource = rs
End Sub
				
back to the top

Complete Code Listing (frmClipboard.frm)

Private Sub Command1_Click()
    Clipboard.SetText Text1.SelText
End Sub

Private Sub Command2_Click()
    Text1.SelText = Clipboard.GetText
End Sub

Complete Code Listing (frmMain.frm)
Private Sub Command1_Click()
    frmADO.Show
End Sub

Private Sub Command2_Click()
    frmClipboard.Show
End Sub
				
back to the top

Verify that the Application Works

  1. Press F5 to start the application.
  2. At the prompt to save the project, click OK.
  3. In Form1, click ADO. A form appears that contains data in a grid. Close this form.
  4. In Form1, click Clipboard.
  5. Click Copy.
  6. Place the insertion point in the text box at the beginning of the text, and then click Paste. You should see the pasted text.
back to the top

Troubleshooting

Visual Basic .NET is a major shift from previous versions of Visual Basic. For many projects, some extensive preparation work is advisable before you upgrade. Refer to the following document for information that may help you to upgrade more easily:
back to the top

REFERENCES

For more information, refer to the following Microsoft Developer Network (MSDN) articles: For more information about how to prepare Visual Basic 6.0 applications for the upgrade to Visual Basic 2005, visit the following MSDN Web site: back to the top

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kbMigration kbHOWTOmaster KB317885 kbAudDeveloper