How do you insert a new line in a text field?

lickuid

Active member
Joined
Nov 6, 2006
Messages
37
Programming Experience
Beginner
I can't find the answer in any search engine... Plz help
 
Use vbNewLine <- VB Constant

Im assuming you want it in a text bxo with MultiLine?

Example:

VB.NET:
txtTextBox.text = "Some text" & vbNewLine & "Some more text under the first line"
 
For the record, in windows, a carriage return is chr 10 and 13 i think?

Same thing as above and vbcrlf is it not?

Just so you know what the function is doing :)
 
but the importance to using ControlChars.NewLine and Environment.NewLine is that if your app is ever to be ran on a system with an OS other than Windows vbNewLine and sending the chr10 + 13 combo will both cause the app to crash

using ControlChars.NewLine and Environment.NewLine means you're making a call to the framework which simply inserts the carrage return character of the OS the app is running on

right now .Net is for Windows only (sorry Mono for Linux just doesnt count yet) so it's not a problem, but it might be later on
 
For the record, in windows, a carriage return is chr 10 and 13 i think?

Same thing as above and vbcrlf is it not?

Just so you know what the function is doing :)


It's actually the other way round.

CR (carriage return) is ascii 13
LF (line feed) is ascii 10

Environment.NewLine and vbNewLine are strings, length 2, of one CR followed by one LF. vbCRLF is old money for the same thing - a string of CR followed by LF. vbCR and vbLF also existed if you wanted just one - necessary for interaction with UNIX systems where just a line feed is used as line separator.


You would be encouraged to use Environment.NewLine rather than vbNewLine, because Environment.NewLine exists in other .NET syntaxes, but vbNewLine does not. By using vb-only versions of cross-language .NET functions and constants, you are reducing your ability to read/cross-train to another .NET syntax; something that may needlessly restrict your career development and cut you off from a wide variety of example code on the web.
 
Back
Top