Upgrading VB 6.0 Applications to VB.NET


The process of upgrading applications from VB 6.0 to VB.NET requires careful planning. While evaluating the application that needs to be migrated, you can categorize the application as:

  • Simple: Migrates easily. Examples include applications with few forms and DLLs.

  • Medium: Migrates with few modifications to existing code. Examples include applications with graphics, menus, and end user-specified controls.

  • Complex: Migrates only after extensive recoding of the existing application. Examples include applications that contain ActiveX Documents or implement Object Linking and Embedding (OLE).

To migrate an application from VB 6.0 to VB.NET:

  1. Evaluate the complexity of the application under consideration. In addition, analyze the feasibility of migration in relation to the time and effort involved in migration.

  2. Modify the code, if necessary, before the upgrade process. This helps reduce reworking after the upgrade process.

  3. Upgrade the VB 6.0 application to VB.NET using the Upgrade wizard.

  4. Modify the migrated code based on the results of the upgrade report that defines the migration issues.

Creating the OrderTracking VB 6.0 Application

The OrderTracking application allows an end user to place an order and check the status of it. The administrator in the OrderTracking application updates the status of the orders. The OrderTracking application consists of two projects:

  • OrderTracking: Allows an end user to select various products, specify the quantity, place an order, and check whether the order is being processed or has been completed. This project also allows the administrator to view a list of all pending orders and update the status of the orders when they are completed. This project contains the following files:

    • frmApplicationManager.frm: Provides the ApplicationManager form that defines the Application Manager window. This window allows an end user to browse through the OrderTracking application.

    • frmLogin.frm: Provides the Login form that defines the Login window. This window allows an end user to specify login credentials and log on to the OrderTracking application.

    • frmPlaceOrder.frm: Provides the PlaceOrder form that defines the PlaceOrder window. This window allows an end user to select products and place an order.

    • frmViewOrderStatus.frm: Provides the ViewOrderStatus form that defines the View Order Status window. This window allows an end user to specify the ID of an order and view the status of the order as either pending or completed.

    • frmUpdateOrderStatus.frm: Provides the UpdateOrderStatus form that defines the Update Order Status window. This window allows the administrator to update the status of an order as completed.

    • Module1.bas: Provides the main() function that establishes a connection with the OrderTracking database and invokes the Login form.


  • OrderStatus: Provides the OrderStatus.cls file that defines the OrderStatus class. This class exposes methods that allow the end user to retrieve the status of a specific order. It also allows the administrator to update the status of an order. The OrderStatus project compiles to OrderStatus.dll to allow you to use it as a component in the OrderTracking project.

Creating the Database Schema

The OrderTracking application uses the OrderTracking database to store information about customers, orders, and products. Listing 5-4 shows the SQL script to generate the database on SQL Server:

Listing 5-4: Creating the OrderTracking Database

start example
 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Customers]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[Customers] GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[OrderInformation]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[OrderInformation] GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Orders]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[Orders] GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Products]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[Products] GO CREATE TABLE [dbo].[Customers] ( [customerId] [int] IDENTITY (1, 1) NOT NULL , [username] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [password] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [firstName] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [lastName] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [address1] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [address2] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [city] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [country] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [zipCode] [varchar] (6) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,  ) ON [PRIMARY] GO CREATE TABLE [dbo].[OrderInformation]  ( [orderId] [int] NOT NULL, [productId] [int] NOT NULL, [qty] [int] NOT NULL  ) ON [PRIMARY] GO CREATE TABLE [dbo].[Orders]  (    [orderId] [int] IDENTITY (1, 1) NOT NULL,    [orderDate] [datetime] NOT NULL,    [amount] [float] NOT NULL,    [customerId] [int] NOT NULL,    [status] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,    [completionDate] [datetime] NULL  ) ON [PRIMARY] GO CREATE TABLE [dbo].[Products]  (    [productId] [int] IDENTITY (1, 1) NOT NULL,    [product] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,    [unitPrice] [float] NOT NULL ,    [qtyInHand] [int] NOT NULL  ) ON [PRIMARY] GO 
end example

The above listing shows how to create the OrderTracking database for the OrderTracking application. The listing creates the following tables in the database:

  • Customers: Stores information about customers, such as customer ID, user name, password, first name, last name, address1, address2, city, country, and postal code.

  • OrderInformation: Stores information about the products included in the order that the end user places. It stores the order ID, the product ID, and the quantity of the ordered product.

  • Orders: Stores information about orders, such as the order ID, the order date, the customer ID, the amount, the date of completion, and order status.

  • Products: Stores information about products, such as the product ID, the product name, unit price, and quantity available.

Creating the OrderStatus Project

To create the OrderStatus project, you need to create the OrderStatus class. The OrderStatus.cls file defines the OrderStatus class that allows the administrator to retrieve and update the status of an order. Listing 5-5 shows the OrderStatus.cls file:

Listing 5-5: The OrderStatus.cls File

start example
 Dim rs As New ADODB.Recordset Dim conn As New ADODB.Connection 'This method retrieves the status of the order. This method returns the status as pending or completed. If the status is completed then the completion date is concatenated to the string to be returned. Public Function RetrieveOrderStatus(ByVal orderId As Integer, ByVal custId As Integer) As String conn.Open "Provider=SQLOLEDB;User ID=sa;password=sa;" & _  "Initial Catalog=OrderTracking;Data Source = 192.168.0.12;" rs.Open "select status,completionDate from orders where order and customer", conn, adOpenStatic If Not rs.RecordCount = 0 Then If rs.Fields("status").Value = "P" Then RetrieveOrderStatus = "pending" Else RetrieveOrderStatus = "completed;" & rs.Fields("completionDate").Value End If Else RetrieveOrderStatus = "" End If End Function 'This method updates the status of the order as completed(in the database as C) Public Sub UpdateOrderStatus(ByVal Id As Integer) conn.Open "Provider=SQLOLEDB;User ID=sa;password=sa;" & _ "Initial Catalog=OrderTracking;Data Source = 192.168.0.12;" conn.Execute "update Orders set status='C', completiondate='" & Date & "' where order" End Sub 
end example

The above listing defines the following methods:

  • RetrieveOrderStatus(): Retrieves the status of an order as pending or completed from the Orders table in the OrderTracking database.

  • UpdateOrderStatus(): Updates the status of an order as completed.

Creating the OrderTracking Project

To create the OrderTracking project, you need to create the ApplicationManager, Login, PlaceOrder, UpdateOrderStatus, and ViewOrderStatus forms, and the Shared module.

Creating the Shared Module

The Module1.bas file defines the Shared module that provides the main() function to initiate the Order Tracking application. Listing 5-6 shows the Module1.bas file:

Listing 5-6: The Module1.bas File

start example
 Public conn As New ADODB.Connection Dim strconn As String 'Variable to store if the end user is an administrator or a customer Public role As String 'Variable to store the id of the customer that logs on to the application Public custId As Integer Public Sub main() On Error GoTo errorhandler strconn = "Provider=SQLOLEDB;User ID=sa;password=sa;" & _ "Initial Catalog=OrderTracking;Data Source = 192.168.0.12;" conn.Open strconn Login.Show vbModal Exit Sub errorhandler: MsgBox ("Error in establishing connection") End Sub 
end example

The above listing defines the main() function that establishes a connection with the OrderTracking database and invokes the Login window.

Creating the Login Window

The Login form defines the Login window, and allows an end user to specify login credentials and log on to the application to place an order. Listing 5-7 shows the frmLogin.frm file that defines the Login form:

Listing 5-7: The frmLogin.frm File

start example
 Private Sub cmdLogin_Click() 'Check whether login credentials are specified Dim rs As New ADODB.Recordset Dim strCmd As String On Error GoTo errorhandler strCmd = "SELECT customerId FROM customers where username='" & txtUsername.Text & _ "' and password='" & txtPassword.Text & "'" rs.Open strCmd, conn, adOpenStatic If Not rs.RecordCount = 0 Then 'The login is succesful If txtUsername.Text = "administrator" Then role = "administrator" Else role = "customer" End If custId = rs.Fields("customerId").Value Else MsgBox "Login failure" txtUsername.SetFocus Exit Sub End If ApplicationManager.Show vbModal txtUsername.Text = "" txtPassword.Text = "" rs.Close Set rs = Nothing Exit Sub errorhandler: MsgBox "Login Error" End Sub 
end example

The above listing defines the cmdLogin_Click() method that executes when an end user specifies the user name and the password and clicks the Login button. This method validates login information and invokes the Application Manager window if the login information is correct.

Figure 5-11 shows the output of Listing 5-7:

this figure shows the login window that allows an end user to specify user name and the password and log on to the ordertracking application.
Figure 5-11: The Login Window

Creating the Application Manager Window

The ApplicationManager form defines the Application Manager window, which allows an end user to access the Place Order window and the View Order Status window. In addition, the ApplicationManager form allows an administrator to access the Update Order Status window. Listing 5-8 shows the frmApplicationManager.frm file that defines the ApplicationManager form:

Listing 5-8: The frmApplicationManager.frm File

start example
 Private Sub Form_Load() If role = "administrator" Then mnuPlaceOrder.Enabled = False mnuViewOrderStatus.Enabled = False mnuUpdateOrder.Enabled = True Else mnuPlaceOrder.Enabled = True mnuViewOrderStatus.Enabled = True mnuUpdateOrder.Enabled = False End If End Sub Private Sub mnuPlaceOrder_Click() PlaceOrder.Show vbModal End Sub Private Sub mnuUpdateOrder_Click() UpdateOrderStatus.Show vbModal End Sub Private Sub mnuViewOrderStatus_Click() ViewOrderStatus.Show vbModal End Sub 
end example

The above listing defines the following methods:

  • Form_Load(): Executes when an end user invokes the Application Manager window. This method checks the login role of the end user and disables the Place Order and View Order Status windows for the administrator and the Update Order Status window for customers.

  • mnuPlaceOrder_Click(): Executes when an end user selects the Place Order menu option to place orders. This method invokes the Place Order window.

  • mnuUpdateOrder_Click(): Executes when an administrator selects Track Order->Update Order Status to update the status of orders. This method invokes the Update Order Status window.

  • mnuViewOrderStatus_Click(): Executes when an end user selects Track Order->View Order Status to view the status of orders. This method invokes the View Order Status window.

Figure 5-12 shows the output of Listing 5-8:

click to expand: this figure shows the application manager window that allows an end user to navigate through the order tracking application.
Figure 5-12: The Application Manager Window

Creating the Place Order Window

The PlaceOrder form defines the Place Order window. This form shows the available products, and allows an end user to select products and place an order. Listing 5-9 shows the frmPlaceOrder.frm file that defines the PlaceOrder form:

Listing 5-9: The frmPlaceOrder.frm File

start example
 Dim rs As New ADODB.Recordset Dim strCmd As String Dim listViewItem As ListItem Private Sub cmbProduct_Click() On Error GoTo errorhandler If Not cmbProduct.Text = "" Then Do While Not rs.EOF If rs.Fields("product").Value = cmbProduct.Text Then 'Retrieve quantity available and unit price of the selected product. txtUnitPrice.Text = rs.Fields("unitPrice").Value Dim itemCount As Integer Dim qtyAvailable As Integer qtyAvailable = rs.Fields("qtyInHand").Value For itemCount = 1 To listViewOrder.ListItems.Count If listViewOrder.ListItems(itemCount).Text = cmbProduct.Text Then qtyAvailable = qtyAvailable - CInt(listViewOrder.ListItems(itemCount).ListSubItems(1).Text) End If Next txtQuantityAvailable.Text = qtyAvailable rs.MoveFirst Exit Do End If rs.MoveNext Loop Exit Sub End If errorhandler: MsgBox "Unable to retrieve information for the selected product.", vbOKOnly, "Retrieval Error" End Sub Private Sub cmdAdd_Click() If Not cmbProduct.Text = "" And Not txtQuantity.Text = "" And Not txtQuantity.Text = "0" Then If Val(txtQuantity.Text) > Val(txtQuantityAvailable.Text) Then MsgBox "Order quantity cannot be greater than available quantity", vbOKOnly, "Please check the value" txtQuantity.SetFocus Exit Sub End If 'Add the product into the listviewOrder as listviewOrder displays the products in your current order Set listViewItem = listViewOrder.ListItems.Add listViewItem.Text = cmbProduct.Text listViewItem.SubItems(1) = txtQuantity.Text listViewItem.SubItems(2) = (Val(txtUnitPrice.Text) * Val(txtQuantity.Text)) txtQuantityAvailable.Text = CInt(txtQuantityAvailable.Text) - CInt(txtQuantity.Text) Dim itemCount As Integer Dim dblTotalAmount As Double For itemCount = 1 To listViewOrder.ListItems.Count dblTotalAmount = dblTotalAmount + Val(listViewOrder.ListItems(itemCount).ListSubItems(2).Text) Next txtAmount.Text = dblTotalAmount txtQuantity.Text = "" cmbProduct.SetFocus End If End Sub Private Sub cmdClose_Click() Unload Me End Sub Private Sub cmdPlaceOrder_Click() On Error GoTo errorhandler If Not listViewOrder.ListItems.Count = 0 Then conn.Execute "insert into orders(orderDate, amount, customerId, status) values('" & Date & "'," & txtAmount.Text & "," & custId & ",'P')" Dim tempRecordSet As New ADODB.Recordset tempRecordSet.Open "select max(orderId) as orderId from orders", conn, adOpenStatic If Not tempRecordSet.RecordCount = 0 Then Dim orderId As Integer orderId = tempRecordSet.Fields("orderId").Value Dim itemCount As Integer For itemCount = 1 To listViewOrder.ListItems.Count Dim productId As Integer 'Retrieve the productId of the selected product Do While Not rs.EOF If rs.Fields("product").Value = listViewOrder.ListItems(itemCount).Text Then productId = rs.Fields("productId").Value rs.MoveFirst Exit Do End If rs.MoveNext Loop 'Save the product wise order information into the database conn.Execute "insert into orderInformation values(" & orderId & "," & productId & "," & listViewOrder.ListItems(itemCount).ListSubItems(1).Text & ")" 'Update the product quantity conn.Execute "update products set qtyInHand=qtyInHand- " & listViewOrder.ListItems(itemCount).ListSubItems(1).Text & " where product" Next End If MsgBox "Your order is saved successfully. Your ORDER ID is " & orderId & ".", vbOKOnly, "Success" listViewOrder.ListItems.Clear txtAmount.Text = "" cmbProduct.SetFocus Exit Sub End If errorhandler: MsgBox "Your order cannot be saved", vbOKOnly, "Database Error" End Sub Private Sub Form_Load() On Error GoTo errorhandler strCmd = "SELECT * FROM products" rs.Open strCmd, conn, adOpenStatic 'Populate the products combo box with the name of the products While Not rs.EOF cmbProduct.AddItem rs.Fields("product").Value rs.MoveNext Wend rs.MoveFirst If Not cmbProduct.ListCount = 0 Then cmbProduct.ListIndex = 0 End If Exit Sub errorhandler: MsgBox "Error while retrieving products", vbOKOnly, "Retrieval Error" End Sub Private Sub Form_Unload(Cancel As Integer) rs.Close Set rs = Nothing cmbProduct.Clear listViewOrder.ListItems.Clear End Sub 
end example

The above listing defines the following methods:

  • Form_Load(): Executes when an end user invokes the Place Order window from the Application Manager window. This method retrieves products from the products table in the database and loads the cmbProduct combo box control with the names of the products.

  • Form_Unload(): Executes when an end user closes the Place Order window. This method clears the items in the cmbProduct combo box control and the listViewOrder listview control.

  • cmbProduct_Click(): Executes when an end user clicks the products list to select a product. This method retrieves the quantity available and the unit price of the selected product from the database.

  • cmdAdd_Click(): Executes when an end user selects the product and the required quantity and clicks the Add to Order button. This method adds the product and the specified quantity to the listViewOrder list view control that represents the Your Current Order list.

  • cmdPlaceOrder_click(): Executes when an end user clicks the Place Order button to place an order for products in the Your Current Order list. This method saves the order information in the orders table in the database.

Figure 5-13 shows the output of Listing 5-9:

click to expand: this figure shows the place order window that allows an end user to select products and place an order.
Figure 5-13: The Place Order Window

Creating the View Order Status Window

The ViewOrderStatus form defines the View Order Status window. This form allows an end user to view the status of an order. Listing 5-10 shows the frmViewOrderStatus.frm file that defines the ViewOrderStatus form:

Listing 5-10: The frmViewOrderStatus.frm File

start example
 Private Sub cmdClose_Click() Unload Me End Sub Private Sub cmdViewStatus_Click() If Not txtOrderId.Text = "" Then Dim strStatus As String On Error GoTo errorhandler 'Creating an object of OrderStatus class of OrderStatus.dll component Dim objOrderStatus As New Order_Status.OrderStatus 'Calling the RetrieveOrderStatus function of OrderStatus class to retrieve the status of the specified order strStatus = objOrderStatus.RetrieveOrderStatus(txtOrderId.Text, custId) If strStatus = "" Then MsgBox "Invalid OrderId", vbOKOnly, "Please check the orderId" Exit Sub End If If strStatus = "pending" Then lblStatus.Caption = "Your order referenced by Order Id " & txtOrderId.Text & " is being processed." Else 'If the status of the order is completed then show the completion date Dim tempArray() As String tempArray = Split(strStatus, ";") lblStatus.Caption = "Your order has been processed. Completion date for your order is " & tempArray(1) & "." End If Exit Sub End If errorhandler: MsgBox "Unable to view the order status", vbOKOnly, "Database Error" End Sub Private Sub txtOrderId_KeyPress(KeyAscii As Integer) If Not IsNumeric(Chr(KeyAscii)) Then If KeyAscii = 8 Then Exit Sub End If KeyAscii = 0 End If End Sub 
end example

The above listing defines the following methods:

  • cmdViewStatus_Click(): Executes when an end user specifies an order ID and clicks the View Status button. This method creates an instance of the Order_Status component and calls the RetrieveOrderStatus() method to retrieve the status of the order that the end user-specified order ID represents.

  • txtOrderId_KeyPress(): Executes when an end user presses any key in the txtOrderId text box. This method checks whether the key pressed by the end user is numeric.

Figure 5-14 shows the output of Listing 5-10:

this figure shows the view order status window that allows an end user to view the status of an order.
Figure 5-14: The View Order Status Window

Creating the Update Order Status Window

The UpdateOrderStatus form defines the Update Order Status window. This form shows all the pending orders, and allows the administrator to update the status of pending orders as completed. Listing 5-11 shows the frmUpdateOrderStatus.frm file that defines the UpdateOrderStatus form:

Listing 5-11: The frmUpdateOrderStatus.frm File

start example
 The frmUpdateOrderStatus.frm File Dim rs As New ADODB.Recordset Dim tempListViewItem As ListItem Private Sub cmdClose_Click() Unload Me End Sub Private Sub cmdUpdateOrder_Click() If Not listViewOrders.ListItems.Count = 0 Then If Not listViewOrders.SelectedItem.Index = 0 Then 'Update the status of the order as completed On Error GoTo errorhandler Dim objOrderStatus As New Order_Status.OrderStatus 'Call the UpdateOrderStatus method of the Order Status class to update the status of the selected order as completed objOrderStatus.UpdateOrderStatus (CInt(listViewOrders.SelectedItem.Text)) listViewOrders.ListItems.Remove listViewOrders.SelectedItem.Index End If Exit Sub Else Exit Sub End If errorhandler: MsgBox "Unable to update the status of the selected order.", vbOKOnly, "Database Error" End Sub Private Sub Form_Load() On Error GoTo errorhandler rs.Open "select orderId, orderDate, amount, customerId from orders where status='P'", conn, adOpenStatic If Not rs.RecordCount = 0 Then While Not rs.EOF Set tempListViewItem = listViewOrders.ListItems.Add() tempListViewItem.Text = rs.Fields("orderId").Value tempListViewItem.SubItems(1) = rs.Fields("orderDate").Value 'A temporary recordset to retrieve the customer name Dim tempRecordSet As New ADODB.Recordset tempRecordSet.Open "select firstname, lastname from customers where customerId= " & rs.Fields("customerId").Value & "", conn, adOpenStatic tempListViewItem.SubItems(2) = tempRecordSet.Fields("firstName").Value & " " & tempRecordSet.Fields("lastName").Value tempListViewItem.SubItems(3) = rs.Fields("amount") tempRecordSet.Close Set tempRecordSet = Nothing rs.MoveNext Wend Exit Sub Else MsgBox "No pending orders found", vbOKOnly, "No pending orders" Unload Me Exit Sub End If errorhandler: MsgBox "Unable to retrieve pending orders.", vbOKOnly, "Retrieval Error" End Sub 
end example

The above listing defines the following methods:

  • Form_Load(): Executes when the administrator invokes the Update Order Status window. This method retrieves information about the pending orders and loads the listViewOrders list view control with the information.

  • cmdUpdateOrder_Click(): Executes when the administrator selects an order from the Pending Orders list and clicks the Update Order button. This method creates an instance of the OrderStatus class and calls the UpdateOrderStatus() method of the OrderStatus class to update the status of the selected order as completed. This method then removes information about that order from the Pending Orders list.

Figure 5-15 shows the output of Listing 5-11:

click to expand: this figure shows the update order status window that allows the administrator to update the status of an order.
Figure 5-15: The Update Order Status Window

Converting the OrderTracking Application to VB.NET Using the Upgrade Wizard

The Visual Studio.NET Integrated Development Environment (IDE) contains a built-in Visual Basic Upgrade wizard that helps migrate VB 6.0 applications to the .NET platform. The Upgrade wizard cannot completely migrate the VB 6.0 application to VB.NET. Many VB 6.0 applications need modifications to specific components before the wizard can upgrade them. The Upgrade wizard reads each line of every file in the project, analyzes them for the different problems that could occur with migration, and assigns an equivalent VB .NET statement. It also creates an upgrade report in the form of an HTML document that defines all the issues of the migration of the VB 6.0 application to the .NET platform. The issues could be error messages and warnings. To upgrade the OrderTracking VB 6.0 application to VB.NET:

  1. Select Start ->Programs ->Microsoft Visual Studio .NET ->Microsoft Visual Studio .NET. The Visual Studio.NET IDE opens.

  2. Select File->Open->Convert. The Convert window, which shows the available upgrade options, appears.

  3. Select the Visual Basic .NET Upgrade wizard and click OK. The Welcome window of the Visual Basic Upgrade wizard opens, as shown in Figure 5-16:

    click to expand: this figure shows the first page of the visual basic upgrade wizard.
    Figure 5-16: The Welcome Screen of the Upgrade Wizard

  4. Click Next. The Choose a Visual Basic 6.0 project file window of the Visual Basic Upgrade wizard opens, as shown in Figure 5-17:

    click to expand: this figure shows the window of the upgrade wizard that prompts you to specify the location of the vb 6.0 project file.
    Figure 5-17: The Choose a Visual Basic 6.0 Project Window of the Upgrade Wizard

  5. Specify the path of the OrderTracking.vbp file and click Next. The Choose a Project Type window of the Visual Basic Upgrade wizard opens, as shown in Figure 5-18:

    click to expand: this figure shows the window of the upgrade wizard in which you specify the type of the project as .exe or .dll.
    Figure 5-18: The Choose a Project Type Window of the Upgrade Wizard

  6. Select the EXE type and click Next. The Specify a Location for Your New Project window of the Visual Basic Upgrade wizard opens, as shown in Figure 5-19:

    click to expand: this figure shows the window of the upgrade wizard that prompts you to specify the location of the new vb.net project.
    Figure 5-19: The Specify a Location for Your New Project Window of the Upgrade Wizard

  7. Specify the path where you want to create the .NET version of the OrderTracking application and click Next. The Ready to Upgrade window of the Visual Basic Upgrade wizard opens, as shown in Figure 5-20:

    click to expand: this figure shows the window of the upgrade wizard that appears before the upgrade process starts.
    Figure 5-20: The Ready to Upgrade Window of the Upgrade Wizard

  8. Click Next to begin the upgrade.

After the Upgrade wizard finishes executing, the OrderTracking application code converts from VB 6.0 code to the equivalent VB.NET code. There are still some issues you need to address. For example, after migrating a VB 6.0 application that contains the ListView control, the wizard generates an incompatible library issue. To fix this, you need to import the corresponding library that supports the ListView control in the converted .NET code. The Upgrade wizard reports these issues in the _UpgradeReport.htm file in the folder that contains the OrderTracking application. This report lists the items that the wizard could successfully upgrade and the items that it could not. The report also includes links to Help topics on the Microsoft Developer Network (MSDN) site to assist you in fixing the errors.

Optimizing Code in the VB.NET Application

After the Upgrade wizard generates the upgrade report highlighting the migration issues and the problem areas, you need to modify the VB.NET code based on the findings. This ensures that the converted application runs as it would have in VB 6.0.

The Upgrade wizard generates the OrderTracking application in .NET. The forms with .frm extensions in the VB 6.0 application convert to Windows forms with the .vb extension. The Upgrade wizard creates the following files in the OrderTracking .NET application:

  • Module1.vb: Provides the Shared_Renamed module that exposes the same functionality as the Shared module in the Module1.bas file. The Upgrade wizard changes the name from Shared to Shared_Renamed.

  • frmLogin.vb: Provides the Login class that exposes the same functionality as the Login form in the frmLogin.frm file.

  • frmApplicationManager.vb: Provides the ApplicationManager class that exposes the same functionality as the ApplicationManager form in the frmApplicationManager.frm file.

  • frmPlaceOrder.vb: Provides the PlaceOrder class that exposes the same functionality as the PlaceOrder form in the frmPlaceOrder.frm file.

  • frmViewOrderStatus.vb: Provides the ViewOrderStatus class that exposes the same functionality as the ViewOrderStatus form in the frmViewOrderStatus.frm file.

  • frmUpdateOrderStatus.vb: Provides the UpdateOrderStatus class that exposes the same functionality as the UpdateOrderStatus form in the frmUpdateOrderStatus.frm file.

  • _UpgradeReport.htm: Provides the upgrade report that includes the issues involved in migrating the OrderTracking VB 6.0 application to the OrderTracking VB.NET application.

  • OrderTracking.log: Provides the XML file that contains the log of the migration of the OrderTracking VB 6.0 application.

The Shared_Renamed Module

The Module1.vb file defines the Shared_Renamed module. The Upgrade wizard inserts a warning before the main() method. The warning states that the application will terminate when Sub Main() finishes. The main() method invokes the Login window by calling the Login.DefInstance.ShowDialog() method.

The Login Window

The Login class in the frmLogin.vb file defines the Login window. Listing 5-12 shows a code fragment in the cmdLogin_Click() method:

Listing 5-12: A Fragment of the cmdLogin_Click() Method

start example
 rs.Close() 'UPGRADE_NOTE: Object rs may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1029"' rs = Nothing 
end example

In the above listing, the Upgrade wizard generates a comment in the form of UPGRADE_NOTE and the rest of the code remains the same as in VB 6.0. The note states that even if you write code to explicitly destroy the rs object, the object might not be destroyed unless the garbage collector reclaims it. The note also provides a link to a file that provides detailed information about the issue.

Note

The Upgrade wizard eliminates the Set keyword of VB 6.0 code because the syntax of VB.NET does not include the Set keyword.

The Application Manager Window

The ApplicationManager class in the frmApplicationManager.vb file defines the Application Manger window. Listing 5-13 shows a code fragment in the frmApplicationManager.vb file:

Listing 5-13: A Fragment of the frmApplicationManager.vb File

start example
 Public Sub mnuPlaceOrder_Popup(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuPlaceOrder.Popup mnuPlaceOrder_Click(eventSender, eventArgs) End Sub Public Sub mnuPlaceOrder_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuPlaceOrder.Click PlaceOrder.DefInstance.ShowDialog() End Sub 
end example

In the above listing, the Upgrade wizard adds the mnuPlaceOrder_Popup() method in addition to the mnuPlaceOrder_Click() method. In the ApplicationManager form in the VB 6.0 application, you define the mnuPlaceOrder_Click() method to invoke the PlaceOrder form from the Place Order menu.

Similarly, methods of other menu items, such as Update Order are also updated. For example, the Upgrade wizard adds the mnuUpdateOrder_Popup() and mnuViewOrderStatus_Popup() methods in addition to the mnuUpdateOrder_Click() and mnuViewOrderStatus_Click() methods.

The Place Order Window

The PlaceOrder class in the frmPlaceOrder.vb file defines the Place Order window. To use the listViewOrder ListView control in the Place Order window, you need to add a reference to the Microsoft Window Common Controls 6.0 (SP6) library. To add a reference to the Microsoft Window Common Controls 6.0 (SP6) library:

  1. Select Project->Add Reference in the Visual Studio .NET IDE. The Add Reference dialog box appears.

  2. Select the COM tab.

  3. Select Component Name as Microsoft Window Common Controls 6.0 (SP6).

  4. Click the Select button and click OK to complete the process and add the reference.

Say, for example, you have the following code in the Windows Forms Designer-generated code region:

 Public WithEvents listViewOrder As Axmscomctllib.AxListView 

Modify the above code to refer to the appropriate library that provides the ListView control that you use in your VB 6.0 application. The following code shows this:

 Public WithEvents listViewOrder As Axmscomctl.AxListView 

Say, for example, you have the following code in the InitializeComponent() method:

 Me.listViewOrder = New Axmscomctllib.AxListView 

Modify the above code, as shown in the following fragment of code:

 Me.listViewOrder = New Axmscomctl.AxListView 

The Upgrade wizard changes the name of the cmbProduct_Click() method of the cmbProduct combo box to the cmbProduct_SelectedIndexChanged() method. The Upgrade wizard also converts the Form_Unload() method to the PlaceOrder_Closed() method, and inserts a warning that states Form event PlaceOrder.Unload has a new behavior.

Note

To use certain controls that Visual Basic 6.0 does not support, you need to add a reference to the Microsoft Window Common Controls 6.0 (SP6) library.

The View Order Status Window

The ViewOrderStatus class in the frmViewOrderStatus.vb file defines the View Order Status window. The Upgrade wizard modifies the code of the txtOrderId_Keypress() method, as shown in Listing 5-14:

Listing 5-14: Modified Code of the txtOrderId_Keypress() Method

start example
 Private Sub txtOrderId_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtOrderId.KeyPress Dim KeyAscii As Short = Asc(eventArgs.KeyChar) If Not IsNumeric(Chr(KeyAscii)) Then If KeyAscii = 8 Then GoTo EventExitSub End If KeyAscii = 0 End If EventExitSub:  If KeyAscii = 0 Then eventArgs.Handled = True End If End Sub 
end example

In the above code, the Upgrade wizard adds the EventExitSub label to the code. The code directs the control to the EventExitSub label when an end user presses the backspace key in the txtOrderId text box.

The Update Order Status Window

The UpdateOrderStatus class in the frmUpdateOrderStatus.vb file defines the Update Order Status window. Say, for example, you have the following code in the Windows Forms Designer-generated code region:

 Public WithEvents listViewOrder As Axmscomctllib.AxListView 

Modify the above code, as shown:

 Public WithEvents listViewOrder As Axmscomctl.AxListVi ew 

For example, say you have the following code in the InitializeComponent() method:

 Me.listViewOrder = New Axmscomctllib.AxListView 

Modify the above code, as shown:

 Me.listViewOrder = New Axmscomctl.AxListView 

After modifying the OrderTracking .NET application, run it. The converted application runs in the same way as it did in VB 6.0.

Note

To learn about the recommendations for upgrading from VB 6.0 to VB.NET, follow the link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvb600/html/vb6tovbdotnet.asp




Migrating Unmanaged Applications to. NET
Migrating Unmanaged Applications to. NET
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 31

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net