Debug Class


Debug Class

Namespace

System.Diagnostics

Creatable

No

Description

The Debug class is used to send messages to the Output Window (called the Immediate Window in VB 6). The Debug class can also send output to other targets (such as text files) referred to as listeners. See the Debug.Listeners Property entry for additional information. The Debug class also allows you to check program logic with assertions.

Because the Debug class's members are shared, you do not need to instantiate a Debug object before accessing its members. The following code fragment, for instance, illustrates a call to the Debug object's WriteLine method:

     Debug.WriteLine(soFar & " iterations through the loop") 

The following table lists some of the more useful and interesting members of the Debug class. Those marked with an asterisk (*) have separate entries in this chapter.

Member

Description

Assert Method *

Tests a condition and reports problems

AutoFlush Property

Indicates whether written data should be flushed to the output stream automatically

Close Method

Flushes and closes each listener (except the Output Window)

Fail Method

Sends an error message to the listeners

Flush Method

Flushes all pending data to the listeners

Indent Method

Increases the current indent level

IndentLevel Property

Indicates the current indent level

IndentSize Property

Identifies the number of spaces for each indent level

Listeners Property *

Lists the collection of listeners

Unindent Method

Decreases the current indent level

Write Method *

Writes text to the debug listeners

WriteIf Method *

Conditionally writes text to the debug listeners

WriteLine Method *

Writes full-line text to the debug listeners

WriteLineIf Method *

Conditionally writes full-line text to the debug listeners


Usage at a Glance

The Debug class features only work in the design-time environment; the statement has no effect in a compiled application. You do not have to remove Debug-related features from your code before release.

Version Differences

The VB 6 Debug object had only two methods: Assert and Print. The .NET Assert method is similar to the VB 6 method of the same name, except that the .NET version displays a message if an expression is False, while the VB 6 version suspends program execution. In .NET, the VB 6 Print method is removed, replaced by the Write, WriteIf, WriteLine, and WriteLineIf methods.

See Also

Debug.Assert Method, Debug.Write Method, Debug.WriteLine Method




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