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:
- 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=<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
- Press CTRL+S to save the form. On the File menu, click Save As. In the Save As dialog box, click Save.
- In the Project Explorer, right-click Project1, click Add, and then click Form. Click Open.
- In the Name field of the Properties dialog box, type frmClipboard.
- From the Toolbox, place a Textbox on the form. In the Text field, type The quick brown fox jumped over the lazy
dog.
- Place a CommandButton below the Textbox. In the Caption field of the Properties dialog box, type Copy.
- Place a second CommandButton on the form. In the Caption field of the Properties dialog box, type Paste.
- 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
- Press CTRL+S to save the form.
- 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.
- In the Name field of the Properties dialog box, type frmMain.
- From the Toolbox, place a CommandButton on the frmMain form. In the Caption field of the Properties dialog box, type ADO.
- Place a second CommandButton on the form. In the Caption field of the Properties dialog box, type Clipboard.
- 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
- Press CTRL+S to save the form.
- In the Solution Explorer, right-click Project1, and then click Project1 Properties. In the Startup Object field, click frmMain, and then click OK.
- 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.
- 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).
- 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. - 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.
- On the Start menu, point to Programs, point to Microsoft Visual Studio .NET, and then click Microsoft Visual Studio .NET.
- 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.
- 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.
- Click Next through each of the steps until the upgrade process begins. The
upgrade takes approximately 30-60 seconds to complete.
- 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.
- 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.
- In the Solution Explorer, note that all of the forms kept
their original names, but the file extension is changed from .frm to
.vb.
- Expand References. Note that references to all of the components that are required
to use legacy Visual Basic and ADO components were added
automatically.
- 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.
- 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.
- 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 ListingsComplete 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- Press F5 to start the application.
- At the prompt to save the project, click OK.
- In Form1, click ADO. A form appears that contains data in a grid. Close this
form.
- In Form1, click Clipboard.
- Click Copy.
- 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: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbvs2005swept kbvs2005applies kbMigration kbHOWTOmaster KB317885 kbAudDeveloper |
---|
|