We help IT Professionals succeed at work.

# Add CrLf to a string of text

sclarkny asked
on
I am writing lines of text to an .ini file. See below:

a.WriteLine ("Email text= Dear " & strfirstname & ", " & _
"Your quote has been attached to this e-mail. Thank you for allowing " & rs("Name") & " the opportunity " & _
"to provide this quotation. Please call us for any of your QUALITY label needs.")

But I need to put a CrLf between each sentence. I tried using vbCrLf but got errors when I tried to save it. How can I embed code to produce a CfLf between each line???????
Comment
Watch Question

## View Solution Only

Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Chr(13) & Chr(10)

mx

Commented:
char(10) & char(13)
Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
"Sentence ... " Chr(13) & Chr(10) & "Another Sentence ..." Chr(13) & Chr(10) ....

mx

Commented:
chr(13) is what you use

a.WriteLine ("Email text= Dear " & strfirstname & ", " & chr(13) &_
"Your quote has been attached to this e-mail. Thank you for allowing " & rs("Name") & " the opportunity " & chr(13) & _
"to provide this quotation. Please call us for any of your QUALITY label needs.")

Commented:
writeline itself adds a vbCrLf at the end, so writing in 3 lines can be used like this.


a.WriteLine ("Email text= Dear " & strfirstname & ", " & _
"Your quote has been attached to this e-mail.")
a.WriteLine ("Thank you for allowing " & rs("Name") & " the opportunity " & _
"to provide this quotation.")
a.WriteLine ("Please call us for any of your QUALITY label needs.")


Commented:
When I added in the chr(13) and chr(10) :
a.WriteLine ("Email text=Dear " & strfirstname & ", " & Chr(13) & Chr(10) & "Your quote has been attached to this e-mail.")
This is going into the body of an email. When I changed the code as above I only saw the following:

Dear Customer,              nothing else was visible.....................

Commented:
I will try that asvforce

Commented:
Are you sure the INI file will handle a CR LF, normally the INI settings are single lines. Have you tried setting this manually in th INI

The vbCrLf (Chr(13) & Chr(10)) has to outside your quotes but you may also need to check vbCr (Chr(13))

Cheers, Andrew

Commented:
Slightly more elegant  to use the constant vbNewLine than the hardcoded ascii codes.  Gives you more portabilty over platforms and codesets.  I know--chr(10) and chr(13) are about as standard/stable as they get.

Commented:
by the way sclarkny: if the text is going in the body of an email, then make sure that the email format type is Text and if it is HTML Type then you will have to use <BR> for breaking lines.

So, if the email format type is HTML then use the below and should work good

a.WriteLine ("Email text= Dear " & strfirstname & ", " & _
"Your quote has been attached to this e-mail. <br>Thank you for allowing " & rs("Name") & " the opportunity " & _
"to provide this quotation. <br>Please call us for any of your QUALITY label needs.")

Commented:
asvforce

I changed the code see below

a.WriteLine ("Email text=Dear " & strfirstname & ", ")
a.WriteLine ("Your quote has been attached to this e-mail.")

but I still only see the first line in the body of the email............If I put the second line on the end of the first line I see it all       like this

a.WriteLine ("Email text=Dear " & strfirstname & ", " & "Your quote has been attached to this e-mail.")

but can't use any carriage control/line feeds.One line runs into the other.

Commented:
can you please try this

a.WriteLine ("Email text= Dear " & strfirstname & ", " & _
"<br>Your quote has been attached to this e-mail. <br>Thank you for allowing " & rs("Name") & " the opportunity " & _
"to provide this quotation. <br>Please call us for any of your QUALITY label needs.")

Commented:
Are you sure the INI file will handle a CR LF, normally the INI settings are single lines.

If this is HTML text you can try </P> (I Think)

Cheers, Andrew

Commented:
Did you try just tje chr(13) code that I posted?
Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
If it's HTML then use
<br>

which is a line feed / cr

mx

Commented:
I wasn't sure when I said </P> I think I mixed it up with MS Word Search for Paragraph Marger /P
Cheers, Andrew

Commented:
asvforce

I tried your suggestion and I now se the following
;Dear Marc, <br>Your quote has been attached to this e-mail. <br>Thank you for allowing Precision Label Corporation the opportunity to provide this quotation. <br>Please call us for any of your QUALITY label needs.

btw..........the email is plain text

Commented:
TextReport

I am putting all of the text in a single line but can't get the LF CR to format the message once I put it in the body of the email.

Commented:
The Chr(13) & Chr(10) or vbCrLf will put a carridge return and lione feed into the INI file not into the email. You need to check with the software you are using (whose INI file it is) to see if there is an acceptable characher of group of characters that can be used to enter the CRLF.

As I have said earlier "Are you sure the INI file will handle a CR LF, normally the INI settings are single lines."

Please advise what you are using to produce your email.

Cheers, Andrew

Commented:
I am using pdfedit995 from software995 to create the email
Commented:
In PDFEdit995 you need to set Email text= in the INI file and create the message body in c:\pdf995\res\utilities\email.txt

Taken from the PDFEdit995 help page

1: Autolaunch
When Autolaunch is checked, pdf995 will automatically display PDF documents in the default PDF viewer when printing is complete. This requires that a PDF viewer is installed.

When Auto-Email is checked, pdf995 will automatically attach a PDF to an email message for sending. This requires that a default MAPI compliant email client such as Microsoft Outlook is specified.

Adding the following to the Parameters section of pdf995.ini will allow you to specify a recipient, text and a subject.

Email Subject=hello world
Email Recipient Address=support@pdf995.com
Email Recipient Name=Pdf995 Support
Email text=this is the text

Auto-Email can also be configured to send via SMTP directly without requiring user input and without displaying the email message. The following parameters are required:

SMTP=1
Email Subject=
Email Recipient Address=
Email Server=
Email Password=
Email From Address=
Email text=

In both cases, if the entry Email text entry is omitted, the message text may be specified in c:\pdf995\res\utilities\email.txt

Cheers, Andrew

Sub Example_CreateTxtFile()
Dim strFileName As String
Dim ff As Long
Dim strData As String
Dim aryData
Dim cnt As Long

strFileName = "c:\pdf995\res\utilities\email.txt"
If Dir(strFileName) <> "" Then Kill strFileName

ff = FreeFile

Open strFileName For Output As #ff
Print #1, Chr(34) & "ID" & Chr(34) & "," & Chr(34) & "Description" & Chr(34)
Print #1, "1," & Chr(34) & "Hello" & Chr(34)
Print #1, "2," & Chr(34) & "World" & Chr(34)
Print #1, "3," & Chr(34) & "OK" & Chr(34)
Close #ff

End Sub


Commented:
Worked GREAT!!!!!!!!!!!!!!!!!!! exactly what I was looking for..............

I didn't know about the email.txt file........thanks for the solution.............

Commented:
I am intrigued to know why you are using PDFEdit995 to send the email rather than outlook or SMTP. This is the first time I have come across it. I have used PDFEdit995 and hte rest of the suite quite a lot but never thought of sending emails.
Cheers, Andrew

Commented:
The original task was to create a PDF and email it. But I was getting various security warnings from Outlook. Using PDFEdit995 allowed me to avoid them.  Besides it was esay to configure and execute from access. And I didn't want to install other 3rd party software to get me around the security warnings. And I wasn't sure if there was a way to send it using SMTP. I didn't setup this server and they are using a 3rd party exchange server for email. This software was well worth the license fee.