Forums

ASP

This topic is locked

Line breaks if using CDONTS

Posted 14 Apr 2002 15:12:16
1
has voted
14 Apr 2002 15:12:16 Peter Gustafsson posted:
Hi!

How do I automaticly get a linebreak after xx number of characters when you send a message with CDONTS in HTML format.

The code for the "body" looks like this:
###########################
HTML1 = "!DOCTYPE HTML PUBLIC""-//IETF//DTD HTML//EN"""
HTML1 = HTML1 & "html"
HTML1 = HTML1 & "head"
HTML1 = HTML1 & "titleThe Title/title"
HTML1 = HTML1 & "/head"
HTML1 = HTML1 & "body bgcolor=""FFFFFF"""
HTML1 = HTML1 & "pfont size =""3"" face=""Arial"""
HTML1 = HTML1 & "strongleftContact request from" & vbCrLf & "font color=""red""" & strName & "/font" & "/left/strongbr"
HTML1 = HTML1 & "table border=""0"" cellpadding=""3"" width=""90%"" align= ""left"""
HTML1 = HTML1 & "trtd E-mail: " & "/tdtd" & "a href=""mailto:"& strEmail &"""/a" & strEmail & "/td/tr"
HTML1 = HTML1 & "trtd Address: " & "/tdtd" & strAddress & "/td/tr"
HTML1 = HTML1 & "trtd Town: " & "/tdtd" & strTown & "/td/tr"
HTML1 = HTML1 & "trtd Postcode: " & "/tdtd" & strPostcode & "/td/tr"
HTML1 = HTML1 & "trtd Telephone: " & "/tdtd" & strTelephone & "/td/tr"
HTML1 = HTML1 & "trtd Fax: " & "/tdtd" & strFax & "/td/tr"
HTML1 = HTML1 & "trtd Price: " & "/tdtd" & strPrice & "/td/tr"
HTML1 = HTML1 & "trtd Special Request: " & "/tdtd" & strSpecialRequest & "/td/tr"
HTML1 = HTML1 & "trtd Arrival Day: " & "/tdtd" & strArrivalDay & "/td/tr"
HTML1 = HTML1 & "trtd Arrival Month: " & "/tdtd" & strArrivalMonth & "/td/tr"
HTML1 = HTML1 & "trtd No Nights: " & "/tdtd" & strNoNights & "/td/tr"
HTML1 = HTML1 & "trtd Apartment Name: " & "/tdtd" & strApartmentName & "/td/tr"
HTML1 = HTML1 & "trtd Number in Party: " & "/tdtd" & strNoParty & "/td/tr"
HTML1 = HTML1 & "trtd Airline: " & "/tdtd" & strAirline & "/td/tr"
HTML1 = HTML1 & "trtd Flight No: " & "/tdtd" & strFlightNo & "/td/tr"
HTML1 = HTML1 & "trtd Arrival Time: " & "/tdtd" & strArrivalTime & "/td/tr"
HTML1 = HTML1 & "/table"
HTML1 = HTML1 & "/body"
HTML1 = HTML1 & "/html"
############################

The critical part is "Special Request" because it is a Text Area. Now, when I receive the mail, the value from "strSpecialRequest" is one (1) long row with no line breaks. I have to scroll horizontal.

I would prefer to set the line breaks automaticly within the width of the table.

Can some one help me with this please??

Peter

Edited by - terra on 14 Apr 2002 15:14:00

Replies

Replied 15 Apr 2002 00:52:47
15 Apr 2002 00:52:47 Owen Eastwick replied:
Modify the line where you assign the from value to the variable strSpecialRequest, something like:

strSpecialRequest = Replace(Request("TextAreaName", VbCrLf, "<BR>"

This will preserve the line breaks as entered by the user.


Regards

Owen.

Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Replied 16 Apr 2002 09:59:31
16 Apr 2002 09:59:31 Peter Gustafsson replied:
Thanks oeastwick for the answer!

The line breaks entered manually by the user, is not the problem, they are visible in the mail.

The problem is if the visitor don´t hit Enter, and writing without any line breaks.

Peter
Replied 16 Apr 2002 12:18:47
16 Apr 2002 12:18:47 Hank Tan-Tenn replied:
If n=number of characters and strText holds the "Special Request" of the email, then I could do the following:
<pre id=code><font face=courier size=2 id=code>
strText = Left(strText,n) & "&lt;BR&gt;" & Right(strBody,Len(strText)-n)
</font id=code></pre id=code>
So say initially strText="Hello, World!" and n=7:

strText (supposedly) becomes "Hello, &lt;BR&gt;World!"

BUT in this form it could do horrible things like chopping a word in half or, worse, if strText is shorter than n, give you an error. So I guess, check for length. Word spacing is more troublesome, but it should be possible to insert a linebreak into the first available space before n.

<img src=../images/dmxzone/forum/icon_smile_question.gif border=0 align=middle>The part I don't get is, shouldn't stuff inside a table cell wrap automatically?

Edited by - akc on 16 Apr 2002 12:22:31
Replied 16 Apr 2002 13:26:09
16 Apr 2002 13:26:09 Peter Gustafsson replied:
Thanks akc for your reply!

You wrote:
<i>The part I don't get is, shouldn't stuff inside a table cell wrap automaticallyi?[/]

I where hope it should, but it´s not!!

I have tried this:
<i>If Len(strSpecialRequest) &gt; 70 Then
Dim strSpecialRequest2
strSpecialRequest2 = Right(strSpecialRequest, Len(strSpecialRequest) - 70)
strSpecialRequest = Left(strSpecialRequest, 70)
If Len(strSpecialRequest2) &gt; 70 Then
Dim strSpecialRequest3
strSpecialRequest3 = Right(strSpecialRequest2, Len(strSpecialRequest2) - 70)
strSpecialRequest2 = Left(strSpecialRequest2, 70)
If Len(strSpecialRequest3) &gt; 70 Then
Dim strSpecialRequest4
strSpecialRequest4 = Right(strSpecialRequest3, Len(strSpecialRequest3) - 70)
strSpecialRequest3 = Left(strSpecialRequest3, 70)
End If
End If
End If
</i>

And this:
[i]HTML1 = HTML1 & "&lt;tr&gt;&lt;td&gt; Special Request: " & "&lt;/td&gt;&lt;td&gt;" & strSpecialRequest & vbCrLF & strSpecialRequest2 & vbCrLF & strSpecialRequest3 & vbCrLF & strSpecialRequest4 & "&lt;/td&gt;&lt;/tr&gt;"</i>

This one is working.
But I am lloking for an easyer way of handling this, because I never know how long the message will be.

I don´t realy understand your answer akc, can you please explain??

Peter

Edited by - terra on 16 Apr 2002 13:29:09

Edited by - terra on 16 Apr 2002 19:35:13
Replied 17 Apr 2002 12:26:37
17 Apr 2002 12:26:37 Hank Tan-Tenn replied:
I kind of regret leading you in that direction, because I really think a cell should auto-wrap its contents. Maybe it depends on the capacity of your (or your clients') email client to display HTML, or perhaps you need to experiment with a simpler version of that table (say, just one row, one cell). After all, I'm sure I've received fairly complicated HTML email with plenty of tables -- and I doubt their creators had to do anything special.

Comes the worst (but it shouldn't), the code you had there could be simplified a bit by using a loop. How many times it goes through it would depend on the # of characters you wish per line.

But as I said before, it w
ould cut off word
s just like these li
nes.

If that's something you or your clients can live with, it's an option.
Replied 19 Apr 2002 17:10:59
19 Apr 2002 17:10:59 Andrew Watson replied:
Aye, It will auto-wrap.

Try specifying the width of the cell.

:: Son, im Thirty.... ::
Replied 19 Apr 2002 19:07:47
19 Apr 2002 19:07:47 Peter Gustafsson replied:
Thanks everyone for your answers!

I am using MS Outlook 2000, so I don´t think it is my client, but I am not sure.

I have tried to specify the width of the cell, with the same consequence.

I have also sent the mail in simple text format, and then I get line breaks!!

My level of attainment, prevent me from doing a loop to use with this. <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Peter

Replied 20 Apr 2002 04:32:15
20 Apr 2002 04:32:15 Hank Tan-Tenn replied:
This function splits text into lines and won't cut off words. Only as a last resort...

<pre id=code><font face=courier size=2 id=code>
strSpecialRequest = "The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. "
Response.Write ChopText(strSpecialRequest,30)


Function ChopText(strText,bytCharPerLine)
Dim arrWords, strChoppedText, bytLenCount, i
arrWords = Split(strSpecialRequest ," "
For i = 0 to UBound(arrWords)
bytLenCount = bytLenCount + Len(arrWords(i)) + 1
If bytLenCount &gt; bytCharPerLine Then
strChoppedText = strChoppedText & "&lt;BR&gt;"
bytLenCount = Len(arrWords(i))
End If
strChoppedText = strChoppedText & arrWords(i) & " "
Next
ChopText = strChoppedText
End Function
</font id=code></pre id=code>

Output (30 char's per line):

The licenses for most
software are designed to take
away your freedom to share and
change it. By contrast, the
GNU General Public License is
intended to guarantee your
freedom to share and change
free software--to make sure
the software is free for all
its users. This General Public
License applies to most of the
Free Software Foundation's
software and to any other
program whose authors commit
to using it. (Some other Free
Software Foundation software
is covered by the GNU Library
General Public License
instead.) You can apply it to
your programs, too.

Reply to this topic