The Different Kinds of EWIs

The Different Kinds of EWIs

There are six types of EWIs. Let s look at the most serious type first.

Upgrade Issues

Upgrade issues are inserted into your code whenever the wizard meets code that will cause a compile error. Upgrade issues mark items that you need to fix before the program will run. A good example is the OLEDrag method. This method has no direct equivalent in Windows Forms, so the following code

Text1.OLEDrag

upgrades to

'UPGRADE_ISSUE: TextBox method Text1.OLEDrag was not upgraded Text1.OLEDrag

Because the OLEDrag method is not a member of the TextBox object, the Text1.OLEDrag statement causes a compile error. The compile error shows in the Task List. The upgrade issue does not. Why not? If it did, you would have two Task List entries for every compiler error instead of one. As you ve learned, at the end of every EWI comment is a link to a Help topic describing how to fix the problem. (In this case, you need to reimplement drag-and-drop capability using the new Windows Forms objects.) We ve removed the hyperlinks from most of the other examples in this book to save space.

Upgrade ToDos

Upgrade ToDos let you know when code has been partially upgraded and needs finishing before it will run. This type of issue commonly arises when you declare a variable of a type that contains a fixed-size array. For example, the following code defines a type called myType that contains a fixed-size array. It then creates an instance of myType called myVariable.

Type myType    myArray(10) As String End Type Sub Main()    Dim myVariable As myType End Sub

In Visual Basic 6, this code works without a problem. In Visual Basic .NET, the Type keyword is renamed Structure; arrays defined with the Structure keyword aren t initialized you have to initialize them yourself. When upgrading this example, the wizard does what it can: It changes the Type keyword to Structure and upgrades the variables within the structure to Visual Basic .NET. It creates a Sub to initialize the arrays. In Visual Basic .NET, structures can now have methods, so the Upgrade Wizard also creates an Initialize method that initializes the arrays for you. The hard work is done. The only step remaining is to write code that calls the Initialize method. This is where you come in. The Upgrade Wizard inserts a ToDo EWI that tells you what you need to do. The upgraded code looks like this:

Structure myType    Dim myArray() As String    'UPGRADE_TODO: "Initialize" must be called to initialize instances    'of this structure.    Public Sub Initialize()       ReDim myArray(10)    End Sub End Structure Public Sub Main()    Dim myVariable As myType End Sub

To make the code work, you need to add a line in Sub Main to call the Initialize method. The following code shows the modified Sub Main:

Public Sub Main()    Dim myVariable As myType    myVariable.Initialize() End Sub

After you make the modification, the code runs as it did in Visual Basic 6. Like upgrade issues, code marked with ToDo comments must be fixed before the program will run.

Run-Time Warnings

Run-time warnings alert you to behavior differences between Visual Basic 6 and Visual Basic .NET. A behavior difference is code that doesn t cause a compile error but might act differently at run time. For example, the Dir function is used to return the list of files or directories inside a particular directory. In previous versions of Visual Basic, Dir also returned . and .. (indicating current directory and parent directory). In Visual Basic .NET, the Dir function doesn t return the . and .. directories. When the following code is upgraded:

Dim myFilename As String     myFilename = Dir("C:\Temp\*.*", vbDirectory)

the Dir function is marked with an upgrade warning:

Dim myFilename As String 'UPGRADE_WARNING: Dir has a new behavior. myFilename = Dir("C:\Temp\*.*", FileAttribute.Directory)

Some programs will work perfectly; some will have problems. If you have code that relies on Dir returning . and .., you need to make modifications. As with other EWIs, a link to Visual Basic .NET help explains the difference and tells you what to do next. Upgrade warnings show up in the Task List.

Design Issues

Design issues identify differences in the design of a form. For example, suppose you have a project with a form, and you ve set the form s OLEDropMode property to Manual. When you upgrade the project, the OLEDropMode property is not upgraded, since there is no direct equivalent in Windows Forms. What happens to OLEDropMode? It is simply ignored and doesn t appear in the upgraded form. Because the code has no appropriate place to put this EWI, the Upgrade Wizard puts the following entry in the Form1 section of the upgrade report: Form property Form1.OLEDropMode was not upgraded. The EWI is associated with a Help topic that explains how to implement drag-and-drop capability in Windows Forms. Because design issues are recorded only in the upgrade report, they do not appear in the Task List.

Upgrade Notes and Global Warnings

We ve just looked at the four most common types of EWI. There are two other less common types of EWI, neither of which shows up in the Task List.

  • Upgrade notes are inserted as friendly memos whenever code is substantially changed.

  • Global warnings are inserted into the upgrade report to alert you to major issues, such as differences in data binding.



Upgrading Microsoft Visual Basic 6.0to Microsoft Visual Basic  .NET
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET w/accompanying CD-ROM
ISBN: 073561587X
EAN: 2147483647
Year: 2001
Pages: 179

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