Replaced Programming Elements

Team-Fly    

 
Visual Basic .NET Unleashed
By Paul Kimmel
Table of Contents
Appendix A.  VB6 Programming Element Changes in VB .NET

Replaced Programming Elements

Several programming elements have been moved, refined, or removed in Visual Basic .NET. This section covers in alphabetical order general programming elements that have changed in some minor way.

Arctangent (Atn)

The arctangent function Atn has been relocated to the System.Math namespace and is called ATan in Visual Basic .NET.

Circle

The Circle statement from VB6 has been refined in the DrawEllipse method defined in the System.Drawing.Graphics namespace.

Debug Printing and Asserting

The debug tools Debug.Assert and Debug.Print have been moved and revised in Visual Basic .NET. Debugging tools exist in the System.Diagnostics namespace and have increased in number and power. Basic asserting and printing are supported in the System.Diagnostics namespace as Debug.Assert and Debug.WriteLine.

DoEvents

If your VB6 application performed many processor- intensive instructions in a loop, you might have called DoEvents after each pass of the loop to ensure that other processes did not become CPU-starved.

DoEvents plays the same role in Visual Basic .NET and has been moved to the System.Windows.Forms.Application namespace.

IsNull

IsNull was used in VB6 to determine whether a variant type contains a value initialized to Null. Comparisons directly to Null evaluate to False. For example, you might think that If(Val = Null) Or If(Val <> Null) is True, either Val is Null or it is not. VB6 evaluates the preceding Or condition and returns Null.

IsNull from VB6 has been removed, and IsDBNull has been added to Visual Basic .NET. IsDBNull evaluates an Object and determines whether the object contains missing or nonexistent data; that is, if the object evaluates to DBNull. Just like IsNull, direct comparisons to DBNull yield DBNull rather than True or False.

As the name IsDBNull suggests, IsDBNull can be used with null data fields and can be written in expressions in the same way you would have used IsNull in VB6.

IsObject

IsObject from VB6 has been replaced with IsReference in Visual Basic .NET. IsReference returns True if an expression returns an object reference with instance assigned to it.

Line

The Line statement from VB6 has been replaced with the Graphics.DrawLine method in the System.Drawing namespace.

 CreateGraphics.DrawLine(Pens.Salmon, 0, 0, Width, Height) 

You can get a Graphics object by calling CreateGraphics. With the Graphics object you can call one of four overloaded DrawLine methods . (The example uses a salmon-colored pen from the Pens collection and draws a diagonal line from the top left to the bottom right of the containing control.) Refer to Chapter 17, "Programming with GDI+," for more on custom drawing and painting in Visual Basic .NET.

LSet and RSet

LSet and RSet from VB6 have been replaced with PadLeft and PadRight, instance methods of the String class. Each method has two versions: one version pads the string with spaces and the second allows you to specify the padding character.

PadLeft inserts padding on the left side of the string and PadRight inserts padding on the right side of the string. Debug.WriteLine("Welcome to Valhalla Tower Material Defender".PadLeft(100)) invokes the PadLeft method of the String object represented by the literal string and inserts the string into a space 100 characters wide. All of the padding occurs to the left of the literal string; the length of the padding is the total width minus the string length.

MsgBox

The MsgBox behavior from VB6 has been supported by the MessageBox.Show method in the System.Windows.Forms namespace. MsgBox is supported by the Microsoft. VisualBasic compatibility namespace.

Tip

The Microsoft.VisualBasic.Interaction namespace contains interactive functions like MsgBox, InputBox, and IIf, carried over from VB6. They are carried over from VB6 but are not part of the CLR and probably will disappear over time.


The Microsoft.VisualBasic namespace is automatically included in Windows form-based applications, and you will see MsgBox (and some examples of MessageBox.Show) used extensively in the demo listings in this book.

Wend

The abbreviated Wend from VB6 has been replaced with the more symmetric End While to terminate a While loop block in Visual Basic .NET.


Team-Fly    
Top
 


Visual BasicR. NET Unleashed
Visual BasicR. NET Unleashed
ISBN: N/A
EAN: N/A
Year: 2001
Pages: 222

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