Microsoft KB Archive/306720

= BUG: Visual Basic .NET or Visual Basic 2005 code examples overwrite text in console window =

Article ID: 306720

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic 2005 Express Edition
 * Microsoft .NET Framework 1.1

-



This article was previously published under Q306720



SYMPTOMS
Many of the Visual Basic code samples in the .NET Framework documentation use the ControlChars.Cr constant to write output to the console. However, this constant, which is intended to separate lines of output in the console, causes the lines of output to be written over each other on a single line in the console.

For example, if a sample intends to write the following output to the console:

First Line

Second Line

if you use the following code: Console.Write( &quot;First Line&quot; & ControlChars.Cr) Console.Write( &quot;Second Line&quot;) the following output results:

Second Line



CAUSE
This problem occurs because many of the Visual Basic samples use the ControlChars.Cr constant, which represents ASCII character 13 (a carriage return), to separate intended lines of output. This character instructs console output to return to the beginning of the current line rather than move to the beginning of the next line.



RESOLUTION
To work around this problem, replace the use of ControlChars.Cr with either the ControlChars.CrLf or ControlChars.NewLine constant. Both of these constants represent a combination of the carriage return (ASCII 13) and line feed (ASCII 10) characters and cause output to move to the beginning of the next line on the console.

After you apply this workaround to the preceding code sample, the new code appears as follows: Console.Write( &quot;First Line&quot; & ControlChars.NewLine) Console.Write( &quot;Second Line&quot;)



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.

Additional query words: CR LF CR/LF kbreadme

Keywords: kbvs2005applies kbvs2005swept kbvs2002sp1sweep kbbug kbpending kbreadme KB306720

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.