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. Here are the victims and their replacements. (We discuss the class library and CLR in Chapter 4 and Chapter 5.)

Constants

The Microsoft.VisualBasic.Constants class in the Base Class Library defines a number of constants, such as the familiar vbCrLf constant, so these can be used as always. However, some constants, such as the color constants vbRed and vbBlue, are no longer directly supported. Indeed, the color constants are part of the System.Drawing namespace’s Color structure, so they are accessed as follows:

Me.BackColor = System.Drawing.Color.BlanchedAlmond

In most cases, to access a particular constant that is not a field in the Microsoft.VisualBasic.Constants class, you must designate the enumeration (or structure) to which it belongs, along with the constant name. For example, the vbYes constant in VB 6 continues to exist as an intrinsic constant in VB .NET. However, it has a counterpart in the MsgBoxResult enumeration, which can be accessed as follows:

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

For a list of all built-in constants and enums, see Appendix D.

String Functions

The LSet and RSet functions have been replaced by the PadLeft and PadRight methods of the System.String class. For instance, the following code pads the name “Donna” with spaces on ...

Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.