There are two special ASCII characters which are interpreted by any visual compo nent (that displays

the text) as a new line. These characters are called LineFee d (ASCII 10) and CarriageReturn (ASCII 13). Since these fall in a catagory calle d White Spaces, means invisible in display environment but have the effect they are for, and cannot be entered through the keyboard, so different computer langu ages implement them differently. For example C/C++ use escape sequences \n for L ineFeed and \r for Carriage return. LineFeed is responsible for moving the inser tion pointer to next line just below its current position, while CarriageReturn returns the insertion pointer to the begining of the line. Since insertion of ne w line normally composed of two actions, namely move down and move to begining, these two character must be inserted in the string of character where new line i s intended. In visual basic these characters are defined as constants vbCr and v bLF for CarriageReturn and LineFeed respectively. There is yet another string co nstant in vb that defines both characters togather and that is vbCrLf. Here is an example that compares C/C++ String with the VB string: C: cprintf("This is first line\r\nThis is next line"); VB: MsgBox "This is first line" & vbCrLf & "This is next line" the result is This is first line This is next line Since C/C++ allows escape sequences, you can embed LineFeed and CarriageReturn w ith in this string as the example shows above. As with VB there are no escape sequenses, rather are string constants. So you ha ve to concatinate three strings: "his is first line" vbCrLf "his is next line" by using VB string concatinators either + or & (& is recomended though for +'s a mbiguity with arithmatic +) thus the string becomes: "This is first line" & vbCrLf & "This is next line" or "This is first line" + vbCrLf + "This is next line" plese note that some functions in C (like printf()) interpret only \n as both \n \r. For your further interest let us use directly the ascii values to get the same e ffect C: cprintf("This is first line%c%cThis is next line",13,10); VB:

MsgBox "This is first line" & chr(13) & chr(10) & "This is next line" or MsgBox "This is first line" + chr(13) + chr(10) + "This is next line" The same effect! Hope this explaination not only will help you getting the effect, but also descr ibe the logic behind

Sign up to vote on this title
UsefulNot useful