Those already familiar with Visual Basic shouldn't have to worry about migrating to Visual Basic.NET. In this article Vaijayantee shows us how to upgrade our existing applications to Visual Basic.NET, different .NET variable types, and her own personal programming recommendations. After reading this article you'll be able to migrate from VB6 to VB.NET in no time!
Migrating to Visual Basic.NET from Visual Basic 6 - Upgrade Report (Page 4 of 7 )
We will have to check up with the Upgrade Report created by the Upgrade Wizard to find out what has happened. The report will be available in the Solutions Explorer. Double click it to open. Expand the Form2 node and you will see that the Upgrade Wizard has not been able to resolve the caption property of the Label1 on Form1.
Visual Basic .NET offers a different Windows Forms package. Which is provided by .NET framework.. Windows Forms and Windows Forms Controls provide a richer interface for developing Windows applications. This means that there are a number of differences between Visual Basic 6 forms and controls and Visual Basic.NET.
Now, open Form1 in the designer by double clicking on it. First thing to be noticed is the ToolTip Control. Remember Visual Basic.NET does not have ToolTip property for the objects? So, what it is trying to tell you is, if you want a ToolTip, add the control to the form.
Let us now examine the code. The End command Button and Command2 Button do not require any modifications to the code. So, has the Upgrade Wizard really done any modifications to the code at all? Check the Form2 Command Button. Where is our call to the Show method of Form2?
Aha, here is where we see the real difference in Visual Basic 6 and Visual Basic.NET approach. Visual Basic.NET treats Forms as objects that belong to a class just like any other object and has to be instantiated before calling its methods. The DefInstance property creates an instance of Form2. This could have been handled by using New keyword, but this is just the Wizardís choice!
Now, open the Form2 code and rectify the error.
Change this code:
Label1.Text = frmdisplay.Label1.Caption
Label1.Text = Form1.DefInstance().Label1.Text
The application now runs smoothly.
Now, why did we have to do the modifications ourselves? Why could the wizard not do it? There are two solid reasons for this.
1) There is no exact one to one corresponding way to write the code between Visual Basic 6 and Visual Basic.NET
2) Visual Basic 6 code supports late binding and Visual Basic.NET does not.
Whenever the code encounters situations where it can not change the code, it prefers to draw programmerís attention to the problem and let the programmer do the job himself. There are four different types of warnings the wizard issues with the help of TO DO comments.
UPGRADE_ISSUES: Indicates compilation errors. These need to be corrected before the application can be compiled and run
UPGRADE_TODO: Though the project compiles well, there will be run time errors
UPGRADE_WARNINGS: Though the project compiles, there may be run time errors
UPGRADE_NOTE: This is a comment for information only. II tells us about any significant modifications handled by the wizard.
Also, when we open the code for Form1, we see it presented differently. Again, Option Explicit is automatically turned on and Option Strict turned off, allowing you to do some implicit conversions.
The block labeled Windows Form Designer also contains code for the design of the form. It tells us how the components on the form are generated, their locations, sizes etc. Though we can manually change this code, it is always a better idea to leave it to the designer. If we need any changes in the look and feel of the form, we could always go back to the designer and make the changes, isnít it?