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



The information in this article applies to:

  • Microsoft Visual Basic Standard Edition for Windows 2.0
  • Microsoft Visual Basic Standard Edition for Windows 3.0
  • Microsoft Visual Basic Professional Edition for Windows 2.0
  • Microsoft Visual Basic Professional Edition for Windows 3.0
  • Microsoft Visual Basic Standard Edition for Windows 1.0

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.

  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


Modification Type:MajorLast Reviewed:12/12/2003
Keywords:kbprb KB74906