Section D.2. Changes to Programming Elements


D.2. Changes to Programming Elements

VB.NET has removed support for several programming elements because the underlying .NET Framework Class Library and the Common Language Runtime (CLR) contain equivalent functionality. Other syntax and usage changes have been made as well.

D.2.1. Constants

Many predefined constants available in VB 6, such as the familiar vbCrLf constant, are now part of VB.NET's Microsoft.VisualBasic.Constants class. They can be used in VB.NET just as they were used in VB 6. However, some constants, such as the color constants vbRed and vbBlue, are no longer directly supported. The color constants are part of the System.Drawing namespace's Color structure and are accessed as follows:

     Me.BackColor = System.Drawing.Color.BlanchedAlmond 

When using most constants, other than those in the Microsoft.VisualBasic.Constants class, you will need to include some or all of their namespace and class name prefix. For example, the vbYes constant in VB 6 continues to exist in VB.NET as a member of the MsgBoxResult enumeration. It can be used as follows:

     If (MsgBoxResult.Yes = MsgBox("OK to proceed?", ... 

For a list of built-in constants and enumerations, see Appendix C.

D.2.2. String Functions

The String function has been removed from VB.NET. Its functionality now appears as part of the String data-type constructor.

     Dim giveThemAnA As New String("A"c, 5) 

which defines a string containing five As. The c modifier in "A"c indicates a character literal (data type Char) as opposed to a standard one-character string (data type String).

D.2.3. Emptiness

In VB 6, the Empty keyword indicated an uninitialized variable, and the Null keyword was used when a variable contained no valid data. VB.NET does not support either keyword but uses the Nothing keyword in both of these cases. The Null keyword continues to be a reserved word in VB.NET, but it has no functionality.

The IsEmpty function is no longer supported in VB.NET; use the IsNothing function instead.

D.2.4. Graphical Functionality

The System.Drawing namespace contains classes that implement graphical methods. Its Graphics class contains methods such as DrawEllipse and DrawLine. As a result, the VB 6 Circle and Line methods, associated with Forms and other drawing surfaces, have been removed.

VB 6's PSet and Scale methods are no longer supported, and they have no direct equivalents in the System.Drawing namespace.

D.2.5. Mathematical Functionality

Mathematical functions are implemented as members of .NET's System.Math class. All VB 6 math functions, such as the trigonometric functions, have been dropped from the VB.NET language itself, replaced with members of System.Math. Typical using is:

     result = Math.Cos(1) 

The Round function has been replaced by the Round method of the System.Math class.

D.2.6. Diagnostics

The System.Diagnostics namespace provides classes related to programming diagnostics. Most notably, the VB 6 Debug object is gone, but its functionality is implemented in the System.Diagnostics.Debug class, which has methods such as Write, WriteLine (replacing Print), WriteIf, and WriteLineIf.

D.2.7. Miscellaneous

Here are a few additional changes to consider.

  • The VB 6 DoEvents statement has been replaced by the DoEvents method of the System.Windows.Forms.Application class.

  • The VB 6 IsNull and IsObject functions have been replaced by the IsDBNull and IsReference methods respectively, both part of the Information class in the Microsoft.VisualBasic namespace.

  • Several VB 6 functions have two versions: a string version (such as trim$) and a variant version (TRim). In VB.NET, these functions are replaced by a single overloaded function. The trim function can now be called directly using either a String or Object argument.




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

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