Microsoft KB Archive/317885

= How to use the Visual Basic Upgrade Wizard =

Article ID: 317885

Article Last Modified on 12/6/2006

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft .NET Framework 1.1

-



This article was previously published under Q317885



IN THIS TASK
SUMMARY
 * Requirements
 * Use the Visual Basic Upgrade Wizard
 * Complete Code Listings
 * Complete Code Listing (frmADO.frm)
 * Complete Code Listing (frmClipboard.frm)
 * Verify that the Application Works
 * Troubleshooting

REFERENCES



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:

http://msdn.microsoft.com/vbasic/learning/migrating/default.aspx?pull=/library/en-us/dnvb600/html/vb6tovbdotnet.asp

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:  On the Start menu, point to Programs, point to Microsoft Visual Studio 6.0, and then click Microsoft Visual Basic 6.0. In the New Project dialog box, click Standard EXE, and then click Open. 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 . If the Toolbox is not open, on the View menu, click Toolbox. 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. From the Toolbox, place a CommandButton on the form below the MSHFlexGrid. In the Caption field of the Properties dialog box, type OK .  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=  and 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 = &quot;Provider=sqloledb;Data Source=localhost;database=northwind;user id= ;password= &quot; cn.Open Dim rs As Recordset Set rs = New Recordset rs.CursorLocation = adUseClient rs.Open &quot;select * from products&quot;, cn   Set MSHFlexGrid1.DataSource = rs End Sub </li> Press CTRL+S to save the form. On the File menu, click Save As. In the Save As dialog box, click Save.</li> In the Project Explorer, right-click Project1, click Add, and then click Form. Click Open.</li> In the Name field of the Properties dialog box, type frmClipboard .</li> From the Toolbox, place a Textbox on the form. In the Text field, type The quick brown fox jumped over the lazy dog .</li> Place a CommandButton below the Textbox. In the Caption field of the Properties dialog box, type Copy .</li> Place a second CommandButton on the form. In the Caption field of the Properties dialog box, type Paste .</li>  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 </li> Press CTRL+S to save the form.</li> 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.</li> In the Name field of the Properties dialog box, type frmMain .</li> From the Toolbox, place a CommandButton on the frmMain form. In the Caption field of the Properties dialog box, type ADO .</li> Place a second CommandButton on the form. In the Caption field of the Properties dialog box, type Clipboard .</li>  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 </li> Press CTRL+S to save the form.</li> In the Solution Explorer, right-click Project1, and then click Project1 Properties. In the Startup Object field, click frmMain, and then click OK.</li> <li>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.</li> <li>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).</li> <li>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.</li> <li>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.</li> <li>On the Start menu, point to Programs, point to Microsoft Visual Studio .NET, and then click Microsoft Visual Studio .NET.</li> <li>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.</li> <li>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: <ul> <li>Create a new project into which your existing project is upgraded.</li> <li>Copy form files and class files into the new project.</li> <li>Provide an upgrade report that lists the components of the project that upgraded successfully and the components that did not upgrade succesfully.</li></ul>

</li> <li>Click Next through each of the steps until the upgrade process begins. The upgrade takes approximately 30-60 seconds to complete.</li> <li>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.</li> <li>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.</li> <li>In the Solution Explorer, note that all of the forms kept their original names, but the file extension is changed from .frm to .vb.</li> <li>Expand References. Note that references to all of the components that are required to use legacy Visual Basic and ADO components were added automatically.</li> <li>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.</li> <li>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.</li> <li> 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 </li></ol>

back to the top

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 = &quot;Provider=sqloledb;Data Source=localhost;database=northwind;user id= ;password= &quot; cn.Open Dim rs As Recordset Set rs = New Recordset rs.CursorLocation = adUseClient rs.Open &quot;select * from products&quot;, 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:

Things to Consider Before Upgrading

back to the top