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

Last reviewed: June 21, 1995
Article ID: Q74906
The information in this article applies to:
  • Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0
  • Microsoft Visual Basic programming system for Windows, version 1.0

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.

  1. In a new project, click the text box icon from the Toolbox (second tool down in the right column).

  2. Click anywhere on the form and drag diagonally to create a text box large enough to hold more then one line of text.

  3. 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.

  4. 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).

  5. On the line below Sub Form_click (), type the following:

          Text1.text = "Hello" + Chr$(13) + "World"
    

  6. 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 "World" is missing.

    For Windows, version 3.1:

          Hello|World
    

  7. To obtain the desired result, you must add a linefeed following the carriage return character, as follows:

          Text1.text = "Hello" + Chr$(13) + Chr$ (10) + "World"
    

    This statement will display the expected result of:

          Hello
          World
    


Additional reference words: 1.00 2.00 3.00
KBCategory: kbprg kbcode kbprb
KBSubcategory: PrgCtrlsStd


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.