PRB: Carriage Return Won't Wrap Lines in Text Box Control
ID: Q74906
|
The information in this article applies to:
-
Microsoft Visual Basic Standard and Professional Editions for Windows, versions 2.0, 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.
- 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 = "Hello" + Chr$(13) + "World"
- 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
- 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 query words:
2.00 3.00
Keywords :
Version :
Platform :
Issue type :