PDA

View Full Version : [SOLVED:] Difference between carriage return and linefeed?



EirikDaude
09-26-2014, 04:17 AM
I am adding new text/captions to some different objects. I want to have linebreaks in the text in question, and tried using something like:

"text" + vbNewLine + "more text"
Since that seemed to be what made the code easiest to read. However, that seems to insert two "newlines", at least when it comes to titles in charts. I figured I should have a look at what other options I have, and according to a different site (http://www.developerfusion.com/thread/23605/carriage-return-line-feed-chars), these are the options for linebreaks in VB(A):

vbCrLf = "\n" # Carriage returnlinefeed combination
vbCr = chr(13) # Carriage return character
vbLf = chr(10) # Linefeed character
vbNewLine = "\n" # Platform-specific new line character; whichever is appropriate for current platform
However I have some difficulty with learning what's the difference between a linefeed and a carriage return, and why one usually (?) combine them. I am guessing that this may be the reason I get one more new line than I want in some circumstances with vbNewLine, because the native new line character is similar to vbCrLf?

Anyway, I don't really have all that much trouble in getting the results I want, I'll just play around a bit with the two other options I have. But I got a bit curious, and would very much appreciate it if someone could give me a bit more information on what the differences between the options are, and if there are any which are more suitable than others?

snb
09-26-2014, 04:38 AM
It's dependent of the application you are working with.

In Word a paragraph will be demarcated by vbCr Chr(13)

In AscII files a line will be demarcated by vbCrLf chr(13)chr(10)

In Excel a multiline in a cell will be demarcated by vbLf Chr(10)

In VBA you can make a multiline in a msgbox using vbLf or vbCr

I don't think there is a standard rule. The software has been developed in different times by different people with different preferences.

EirikDaude
09-26-2014, 04:44 AM
Heh, nothing is ever easy :) Thanks for the information, at any rate!