Microsoft KB Archive/74906

= PRB: Carriage Return Won't Wrap Lines in Text Box Control =

Article ID: 74906

Article Last Modified on 12/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 1.0 Standard Edition

-



This article was previously published under Q74906



SYMPTOMS
Under Microsoft Windows version 3.0, using Chr$(13) (the carriage return character) alone to create a line wrap to the next line in a Visual Basic text box control causes the character following the carriage return to be removed from a multiline text box. Under Microsoft Windows, version 3.1, it will cause a pipe character '|' to be displayed in the place of the CHR$(13).



RESOLUTION
To wrap to the next line correctly, you must use both a carriage return and a linefeed -- Chr$(13) and Chr$(10).



STATUS
This behavior is by design.



MORE INFORMATION
The correct method to create a line wrap is to use a carriage return character followed by a linefeed character, Chr$(13) + Chr$(10). The Windows text box expects to find this sequence and assumes that the character following the carriage return is a linefeed, thus removing the following character as if it were a linefeed.

The following steps show the results of using just the carriage return, and the results of using both carriage return and linefeed characters in a text box.

 In a new project, click the text box icon from the Toolbox (second tool down in the right column). Click anywhere on the form and drag diagonally to create a text box large enough to hold more then one line of text. From the Properties bar (below the main menu) scroll down to Multiline, then choose the Settings box for that Multiline property (also on the Properties bar below the menu) and choose True. The text box can now accommodate several lines of text. Double-click anywhere in the form outside of the text box to bring up the Form_click code window (or use the F7 function key).  On the line below Sub Form_click, type the following: Text1.text = &quot;Hello&quot; + Chr$(13) + &quot;World&quot;  Press F5 to run the newly created application, then click anywhere in the form outside the text box. The following text will appear.

For Windows, version 3.0:

Hello

orld

NOTE: The W of &quot;World&quot; is missing.

For Windows, version 3.1:

Hello|World

</li>  To obtain the desired result, you must add a linefeed following the carriage return character, as follows: Text1.text = &quot;Hello&quot; + Chr$(13) + Chr$ (10) + &quot;World&quot; This statement will display the expected result of:

Hello

World

</li></ol>

Additional query words: 2.00 3.00

Keywords: kbprb KB74906

-

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

© Microsoft Corporation. All rights reserved.