Home > Articles

0672321300

Upgrading from VB 6.0

Although it is recommended that you not use the compatibility classes directly, the VB 6.0 Upgrade Wizard might use them when upgrading projects from VB 6.0 to VB .NET. Before upgrading a previous project to VB .NET, you must decide whether you should.

Basically, this question must be answered on a project-by-project basis, but for most projects the answer will be no. The reasons for this are as follows:

  • As evidenced by this chapter, many changes have been made to the structure of the language, and although the Upgrade Wizard makes some automatic corrections for these, it likely will not address all of them. In fact, Microsoft recommends several coding practices that should be employed in existing VB 6.0 projects for the upgrade to proceed more smoothly (http://msdn.microsoft.com/library/default.asp?URL=/library/techart/vb6tovbdotnet.htm). Because not all VB 6.0 projects follow these guidelines, there will be plenty of places where you need to change the code. This also will entail extensive testing, which, in the final analysis, might be more effort than is warranted given the reasons listed here.

  • VB .NET and the Services Framework present totally new ways of dealing with certain scenarios. For example, ADO.NET exposes a new disconnected programming model for database applications that is different from the classic ADO model. When you upgrade a VB 6.0 project, the Upgrade Wizard does not convert your code to ADO.NET, rather it uses a translation layer (COM Interop, discussed in Chapter 9, "Accessing Component Services") to broker calls between managed code and classic COM components such as ADO. In addition, new project types such as the Windows Service application allow you to write applications in a different way. An upgraded NT service project that relies on a third-party ActiveX control or the Win32 API will not take advantage of the inherent integration. As a result, you won't get the benefits of the Services Framework by upgrading your VB 6.0 project.

  • As a follow-on to the previous point, the Web Services model, perhaps the most important concept in .NET (discussed in Chapter 11, "Building Web Services"), will not automatically be integrated into your project. The design and implementation of Web Services likely will require redesign and implementation of your solutions.

  • As discussed in Chapters 4 and 6 particularly, VB .NET contains entirely new language constructs, such as implementation inheritance and structured exception handling. The Upgrade Wizard will not add these powerful features to your code. That is a task for subsequent development.

  • Although the .NET platform is a new and interesting way to develop applications, existing VB 6.0 applications will be supported and will run just fine on Windows operating systems. In fact, VB 6.0 and VS .NET can coexist peacefully on the same machine.

  • As a corollary to the previous point, if your applications follow a multitiered architecture where the data access and business services are decoupled from the user interface, you can take a piecemeal approach and recode the user interface in ASP.NET to take advantage of its features while using COM Interop to call existing COM components that perform business logic and data access. In this way, the application needn't be reworked from the ground up, and other applications that rely on your middleware will continue to function.

  • In any case, the Upgrade Wizard cannot upgrade certain types of projects in VB 6.0 (and yes, the project must have been previously saved in VB 6.0). For example, DHTML applications, data binding with DAO and RDO, and ActiveX document projects will not be upgraded, whereas WebClasses will require significant modification.

So what is the recommendation? Probably only the simplest of applications, such as utility applications, are suited for a simple upgrade, compile, and run. Any project that interoperates with other COM components and external DLLs will require significant work that is tantamount to a rewrite. As a result, I would use the Upgrade Wizard simply as a starting point and more of a check on syntactical changes. For example, you might run the Upgrade Wizard on your data access COM component to see how the ADOMD library is referenced and accessed in VB .NET. However, then you need to do the work of integrating new language features and Services Framework classes as appropriate.

Using the Upgrade Wizard

To run the wizard, you simply need to open the VB 6.0 project files (.vbp) in VB .NET and follow the wizard steps. The wizard analyzes your code and performs certain automatic translations—for example, from Long to Integer and Variant to Object. In addition, it places various warnings and errors as comments in the code. These are places you'll need to concentrate on. To summarize the upgrade, an HTML file is added to the project, which shows each error and provides additional information.

To illustrate the upgrade process, consider an ActiveX DLL project created in VB 6.0 called SearchSortUtils. This project contains a single class module called Algorithms that implements BubbleSort, ShellSort, and BinSearch (binary search) methods that work on zero-based multidimensional arrays. This project was run through the Upgrade Wizard, and Figure 3.1 shows the resulting upgrade report.

NOTE

The SearchSortUtils VB 6.0 project files can be downloaded from the companion Web site.

As you'll notice from the report, 0 errors and 57 warnings were issued in a project that comprised less than 275 lines in VB 6.0. The 57 warnings were primarily related to the fact that the wizard could not find a default property on variables that were of type Variant and converted to Object.

Figure 3.1 This HTML document shows that 57 issues were found when upgrading the SearchSortUtils project.

NOTE

The Upgrade Wizard can resolve parameterless default properties for classes that are referenced, but it cannot do so for objects that are late-bound, hence the warnings discussed previously.

Because this is a simple project that does not contain any references to COM components, ActiveX controls, or other external code, the project was immediately able to be compiled and run in VB .NET. However, to make the code more VB .NET friendly, and to illustrate the kinds of changes you'll make to your own code, the following changes were made:

  • The wizard changed references from Variant to Object. Because this class used Variant to refer to arrays, Object was changed to Array.

  • The methods were changed to shared methods so that a client does not have to create an instance of the class to use its methods.

  • Because VarType is obsolete, the references to the VarType function were changed to the GetType function and the GetType method of the variable being inspected.

  • The function return syntax was changed to use the Return statement rather than the name of the function.

  • Overloaded signatures were created for each of the methods rather than Optional arguments.

Listing 3.4 shows the completely upgraded project with the preceding changes.

Listing 3.4  Upgraded Utility Project. This listing shows the syntax of the upgraded SearchSortUtil project.

Option Strict Off
Option Explicit On

Public Class Algorithms

  ` Searching and sorting algorithms for zero-based
  ` variant two dimensional arrays where the first
  ` dimension is the columns and the second is the rows

  `******************************************************************
  Public Overloads Shared Sub BubbleSort(ByRef varArray As Array)
    Call BubbleSort(varArray, False, 0)
  End Sub

  Public Overloads Shared Sub BubbleSort(ByRef varArray As Array, _
    ByVal flDescending As Boolean)
    Call BubbleSort(varArray, flDescending, 0)
  End Sub

  Public Overloads Shared Sub BubbleSort(ByRef varArray As Array, _
    ByVal flDescending As Boolean, ByVal pIndex As Short)

    Dim i As Integer
    Dim j As Integer
    Dim lngUB As Integer
    Dim lngLB As Integer
    Dim lngUB1 As Integer
    Dim lngLB1 As Integer
    Dim z As Integer
    Dim varArrTemp As Object

    ` Cache the bounds
    lngUB = UBound(varArray, 2)
    lngLB = LBound(varArray, 2)

    lngUB1 = UBound(varArray, 1)
    lngLB1 = LBound(varArray, 1)

    ` If the optional index is 0 then set it to the
    ` lower bound (sort by first column)
    If pIndex = 0 Then
      pIndex = LBound(varArray, 1)
    End If

    ` Loop through the array using the second
    ` dimension of the array (the rows)
    For i = lngLB To lngUB
      For j = lngLB To lngUB - 1 - i
        ` Compare the items in the array
        If CompMe(varArray(pIndex, j), _
          varArray(pIndex, j + 1), flDescending) Then
          ReDim varArrTemp(UBound(varArray, 1), 0)

          ` If the first item is larger then swap them
          For z = lngLB1 To lngUB1
            varArrTemp(z, 0) = varArray(z, j)
          Next z
          For z = lngLB1 To lngUB1
            varArray(z, j) = varArray(z, j + 1)
          Next z
          For z = lngLB1 To lngUB1
            varArray(z, j + 1) = varArrTemp(z, 0)
          Next z
        End If
      Next j
    Next i

  End Sub


  `******************************************************************
  Public Overloads Shared Sub ShellSort(ByRef varArray As Array)
    Call ShellSort(varArray, False, 0)
  End Sub

  Public Overloads Shared Sub ShellSort(ByRef varArray As Array, _
    ByVal flDescending As Boolean)
    Call ShellSort(varArray, flDescending, 0)
  End Sub

  Public Overloads Shared Sub ShellSort(ByRef varArray As Array, _
    ByVal flDescending As Boolean, ByVal pIndex As Short)

    Dim i As Integer
    Dim lngPos As Integer
    Dim varTemp As Object
    Dim lngLB As Integer
    Dim lngUB As Integer
    Dim lngSkip As Integer
    Dim flDone As Boolean
    Dim z As Integer
    Dim varArrTemp As Object


    ` If the optional index is 0 then set it to the
    ` lower bound (sort by first column)
    If pIndex = 0 Then
      pIndex = LBound(varArray, 1)
    End If

    ` Cache the lower and upper bounds
    lngLB = LBound(varArray, 2)
    lngUB = UBound(varArray, 2)

    ` Assign the skip count
    Do
      lngSkip = (3 * lngSkip) + 1
    Loop Until lngSkip > lngUB

    Do
      ` Decrement the skip each time through the loop
      lngSkip = lngSkip / 3

      ` Check the remainder of the array
      For i = lngSkip + 1 To lngUB
        ` Pick up the current value
        varTemp = varArray(pIndex, i)
        ReDim varArrTemp(UBound(varArray, 1), 0)

        For z = LBound(varArray, 1) To UBound(varArray, 1)
          varArrTemp(z, 0) = varArray(z, i)
        Next z
        lngPos = i

        ` If we've reached the beginning then increment the
        ` skip count but signal that this is the last pass
        If lngSkip = 0 Then
          lngSkip = 1
          flDone = True
        End If
        ` Check to see if the preceding element is larger
        Do While CompMe(varArray(pIndex, lngPos - lngSkip), _
          varTemp, flDescending)
          ` If so then slide it in
          For z = LBound(varArray, 1) To UBound(varArray, 1)
            varArray(z, lngPos) = varArray(z, lngPos - lngSkip)
          Next z
          lngPos = lngPos - lngSkip
          If lngPos <= lngSkip Then Exit Do
        Loop
        ` Put the current value back down
        For z = 0 To UBound(varArray, 1)
          varArray(z, lngPos) = varArrTemp(z, 0)
        Next z
      Next i

    Loop Until lngSkip = lngLB Or flDone

  End Sub

  `******************************************************************
  Private Shared Function CompMe(ByVal pArg1 As Object, _
   ByVal pArg2 As Object, ByVal pDesc As Boolean, _
   Optional ByRef pEqual As Boolean = False) As Boolean

    ` If descending then do a less than compare
    If pDesc Then
      ` If equality is specified then use an equal sign
      Select Case pEqual
        Case True
          ` Check if its a string to do a string compare
          If pArg1.GetType Is GetType(System.String) Then
            If UCase(pArg1) <= UCase(pArg2) Then
              Return True
            End If
          Else
            If pArg1 <= pArg2 Then
              Return True
            End If
          End If
        Case False
          ` If not specified then do a < compare
          If pArg1.GetType Is GetType(System.String) Then
            If StrComp(pArg1, pArg2, CompareMethod.Text) = -1 Then
              Return True
            End If
          Else
            If pArg1 < pArg2 Then
              Return True
            End If
          End If
      End Select
    Else
      ` If ascending doing a greater than compare
      Select Case pEqual
        Case True
          ` Check if its a string first
          If pArg1.GetType Is GetType(System.String) Then
            If UCase(pArg1) >= UCase(pArg2) Then
              Return True
            End If
          Else
            If pArg1 >= pArg2 Then
              Return True
            End If
          End If
        Case False
          ` Check if its a string
          If pArg1.GetType Is GetType(System.String) Then
            If StrComp(pArg1, pArg2, CompareMethod.Text) = 1 Then
              Return True
            End If
          Else
            If pArg1 > pArg2 Then
              Return True
            End If
          End If
      End Select
    End If

    Return False

  End Function


  `******************************************************************
  Public Overloads Shared Function BinSearch(ByRef varArray As Array, _
    ByVal varSearch As Object, ByVal pIndex As Short) As Integer
    Call BinSearch(varArray, varSearch, pIndex, False)
  End Function

  Public Overloads Shared Function BinSearch(ByRef varArray As Array, _
    ByVal varSearch As Object, ByVal pIndex As Short, _
    ByVal flPartial As Boolean) As Integer

    Dim lngLow As Integer
    Dim lngUpper As Integer
    Dim lngPos As Integer

    ` Set the upper and lower bounds of the array
    lngLow = LBound(varArray, 2)
    lngUpper = UBound(varArray, 2)

    Do While True
      ` Divide the array to search
      lngPos = (lngLow + lngUpper) / 2

      ` Look for a match
      If flPartial Then
        ` If partial is specified then do a comparison
        ` on the substring since it should be a string
        If StrComp(Mid(varArray(pIndex, lngPos), 1, Len(varSearch)), _
           varSearch, CompareMethod.Text) = 0 Then
          ` If we've found it then get out
          Return lngPos
        End If
      Else
        ` Check to see if its a string
        If varSearch.GetType Is GetType(System.String) Then
          If StrComp(varArray(pIndex, lngPos), varSearch, _
            CompareMethod.Text) = 0 Then
            ` If we've found it then get out
            Return lngPos
          End If
        Else
          If varArray(pIndex, lngPos) = varSearch Then
            ` If we've found it then get out
            Return lngPos
          End If
        End If
      End If
      ` Check to see if its the last value to be checked
      If lngUpper = lngLow + 1 Then
        lngLow = lngUpper
      Else
        ` If we get to the lowest position then it's not there
        If lngPos = lngLow Then
          Return -1
        Else
          ` Determine whether to look in the upper or
          ` lower half of the array
          If varSearch.GetType Is GetType(System.String) Then
            If StrComp(varArray(pIndex, lngPos), varSearch, _
              CompareMethod.Text) = 1 Then
              lngUpper = lngPos
            Else
              lngLow = lngPos
            End If
          Else
            If varArray(pIndex, lngPos) > varSearch Then
              lngUpper = lngPos
            Else
              lngLow = lngPos
            End If
          End If
        End If
      End If
    Loop

  End Function
End Class

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020