Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a newline in a string.

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
I am trying to create a mail message body, that will give me multiple lines... I tried this:
Code:
msgBody += Session("Name") & " (" & Session("id") & ") has ordered the following Supplies." & CHR(10) & CHR(13)
if candid.Text <> &quot;&quot; then msgBody += candid.Text & &quot; Candid Envelopes.&quot; & CHR(10) & CHR(13)
if senior.Text <> &quot;&quot; then msgBody += senior.Text & &quot; Senior Envelopes.&quot; & CHR(10) & CHR(13)

It worked at first, but now everything goes on the same line.

(Actually, at first I had only CHR(10), but now that doesn't even work.)

How can I create something that gives me multiple lines?
 
Just use the vb variable vbCrLf.

Imports System.Text
Dim sb as new StringBuilder()

sb.Append(&quot;This is the first line&quot;)
sb.Append(vbCrLf)
sb.Append(&quot;This is the second line&quot;)

something = sb.toString


The other thing to do if this is an email message is to send it using html format.

Imports System.Text
Dim sb as new StringBuilder()

sb.Append(&quot;<HTML><HEAD></HEAD><BODY>&quot;)
sb.Append(&quot;This is the first line&quot;)
sb.Append(&quot;<HR>&quot;)
sb.Append(&quot;This is the second line&quot;)
sb.Append(&quot;</BODY></HTML>&quot;)

something = sb.toString

Just make sure to send the message in html format
myMessage.BodyFormat = Mail.MailFormat.Html

See faq796-2119

HTH That'l do donkey, that'l do
[bravo] Mark
 
K, now, stringbuilder..... that's more resource friendly, right? I mean, I believe I read somewhere that it uses the same memory space, whereas += creates a new memory space for each addition. (I just couldn't remember the name.)
 
Ya it's supposed to be better for performance. I also like it because your code looks so much cleaner. Easier to read.

Paul did an FAQ on that one. Here's the link
faq855-1882 That'l do donkey, that'l do
[bravo] Mark
 
environment.newline

is supposed to work, as well, but seems to be a bit sketchy.

when it does work properly, though, it makes for some very readable code.

:)
paul
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top