Link to home
Start Free TrialLog in
Avatar of pingeyeg
pingeyeg

asked on

Wrapping text

What code is used to make the text have a line break after so many characters when displayed.  Right now when you click on an email message the text stays on one line and stretches the column too long.
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

pingeyeg,

In vbscript it is the constant vbcrlf.  For example ...

Response.Write "This first line" & vbcrlf
Response.Write "New line" & vbcrlf

Let me know if you have any questions or need more information.

b0lsc0tt
This may help you to remember that constant.  It is short for "Visual Basic Carriage Return Line Feed."
Avatar of pingeyeg
pingeyeg

ASKER

Ok, makes since.  The only problem is how to place it in with this:

" & rs("message") & vbcrlf & "
Function lineBreak(text, lineLength, forceBreaks)
     Dim x, i, vbCrLf
     vbCrLf = Chr(13) & Chr(10)
     lineBreak = ""
     Do
          For x = 1 to Len(text)
               If mid(text, x, 2) = vbCrLf Then
                     lineBreak = lineBreak & left(text, x -1) & vbCrLf
                     If Len(text) > x + 2 Then
                          text = mid(text, x+2)
                     Else
                          text = ""
                     End If
                     Exit For
               ElseIf x = lineLength Then
                    If forceBreaks Then
                         lineBreak = lineBreak & left(text, x) & vbCrLf
                         If Len(text) > x + 1 Then
                              text = mid(text, x+1)
                         Else
                              text = ""
                         End If
                         Exit For
                    Else
                         For i = x to 1 step -1
                              If mid(text, i, 1) = " " Then
                                   Exit For
                              End If
                         Next
                         If mid(text, i, 1) = " " Then
                              lineBreak = lineBreak & left(text, i) & vbCrLf
                              If Len(text) > i + 1 Then
                                   text = mid(text, i+1)
                              Else
                                   text = ""
                              End If
                         Else
                              lineBreak = lineBreak & left(text, x) & vbCrLf
                              If Len(text) > x + 1 Then
                                   text = mid(text, x+1)
                              Else
                                   text = ""
                              End If
                         End If
                         Exit For
                    End If
               End If
          Next
          If Len(text) <= lineLength Then
               lineBreak = lineBreak & text & vbCrLf
               text = ""
          End If
     Loop Until text = ""
End Function


Call it using lineBreak(yourText, NumberOfCharactersPerLine, ForceBreaks)
I've been playing around with some string manipulation but haven't quite figured it out just yet. I'll get it and will post when (or if) I do. There has to be some combination of left() then a replace() after to swap in the vbcrlf. But why not, instead of that, just write out your email to a fixed-size table cell. You can set the size to whatever you want and encode it to force a wrap or justify all you want.

Another option would be to "wrap physical" to a form textarea and use some CSS to hide the borders of the form.
shadie, can I do this to my asp code?
CyrexCore2k, can you help me with the call by placing it withing this code I have?

"<tr><td class=""message_td_font"">Message:</td><td colspan=""3"">" & rs("message") &  " </td></tr>" &_

I really apreciat it.
Slight fix

Function lineBreak(text, lineLength, forceBreaks)
     Dim x, i, vbCrLf
     vbCrLf = Chr(13) & Chr(10)
     lineBreak = ""
     Do
          For x = 1 To Len(text)
               If Mid(text, x, 2) = vbCrLf Then
                     lineBreak = lineBreak & Left(text, x - 1) & vbCrLf
                     If Len(text) > x + 2 Then
                          text = Mid(text, x + 2)
                     Else
                          text = ""
                     End If
                     Exit For
               ElseIf x = lineLength Then
                    If forceBreaks Then
                         lineBreak = lineBreak & Left(text, x) & vbCrLf
                         If Len(text) >= x + 1 Then
                              text = Mid(text, x + 1)
                         Else
                              text = ""
                         End If
                         Exit For
                    Else
                         For i = x To 1 Step -1
                              If Mid(text, i, 1) = " " Then
                                   Exit For
                              End If
                         Next
                         If Mid(text, i, 1) = " " Then
                              lineBreak = lineBreak & Left(text, i) & vbCrLf
                              If Len(text) >= i + 1 Then
                                   text = Mid(text, i + 1)
                              Else
                                   text = ""
                              End If
                         Else
                              lineBreak = lineBreak & Left(text, x) & vbCrLf
                              If Len(text) >= x + 1 Then
                                   text = Mid(text, x + 1)
                              Else
                                   text = ""
                              End If
                         End If
                         Exit For
                    End If
               End If
          Next
          If Len(text) <= lineLength Then
               lineBreak = lineBreak & text & vbCrLf
               text = ""
          End If
     Loop Until text = ""
End Function
"<tr><td class=""message_td_font"">Message:</td><td colspan=""3"">" & lineBreak(rs("message"), 50, True) &  " </td></tr>"

If the lines are still too long try changing 50 to say 30 or 20 and if they're too short put it up to 80

good luck.
+ Make sure you place the function code somewhere (up at the very top is best) in your current script.
when you ask me if you can do it in your asp code, what part are you referring to? Yes, both the form and the table can be done in your asp.
you posted:
"<tr><td class=""message_td_font"">Message:</td><td colspan=""3"">" & rs("message") &  " </td></tr>" &_

why not change it to:

"<tr><td class=""message_td_font"" width=500>Message:</td><td colspan=""3"">" & rs("message") &  " </td></tr>" &_

and the table (cell) will automatically wrap rs("message") for you
I'm getting a runtime error '800a000d'

Type mismatch: 'lineBreak'

/dev/showmessages.asp, line 118
or:


"<form><tr><td class=""message_td_font"">Message:</td><td colspan=""3""><textarea cols=""50"" rows=""10"" wrap=""VIRTUAL"">
" & rs("message") &  " </textarea></td></tr></form>" &_

and come up with some creative CSS to hide the appearance of the textarea
How could that be if you have the width=500 in the wrong cell?  I tried putting that in the rs("message") cell, but it did nothing to help.
I see what you mean, but that is not the look I am gonig for.  I do not want to show any boxes or scrollbars.
CyrexCore2k, did you see my message to you?
Ping

Whats on line 118

And did you add the function to your script?
I added the function to my script.

Line 118 is this:   Response.Write "<table align=""center""  cellpadding=""0"" cellspacing=""0"">" &_
alright what about lines 110 to say 130?
<% Dim MyAccount
Dim CurUserMail
Set MyAccount = Server.CreateObject("ADODB.Connection")
ConnStr = "DRIVER={Microsoft Access Driver (*.mdb)};pwd=password;"
ConnStr = ConnStr & "DBQ=" & Server.MapPath("/dev/students.mdb")
MyAccount.Open(ConnStr)

CurUserMail = MyAccount.execute("select email from access where email = '" & Your_Email & "'")(0)

SQLtemp = "SELECT * FROM messages, access WHERE access.email = messages.email_from AND messages.ID = " & Request.QueryString("MessageID") & " AND messages.email_to = '" & Request.Cookies("email_to") & "' AND messages.data_entry = messages.data_entry"
Set rs = MyAccount.execute(SQLtemp)

'Response.Write "MessageID: " & Request.QueryString("MessageID") & "<br/>"
'    Response.Write "Email_to: " & Request.Cookies("email_to") & "<br/>"
'      Response.Write "Email_from:" & Request.Cookies("email_from") & "<br/>"
'      Response.Write "Message:" & Request.Cookies("message") & "<br/>"
'    Response.Flush

while not rs.eof

If Request.Cookies("email_to") = rs("email_to") Then
if those are lines 110 to 130 where is

Response.Write "<table align=""center""  cellpadding=""0"" cellspacing=""0"">" &_

???
<% Dim MyAccount
Dim CurUserMail
Set MyAccount = Server.CreateObject("ADODB.Connection")
ConnStr = "DRIVER={Microsoft Access Driver (*.mdb)};pwd=password;"
ConnStr = ConnStr & "DBQ=" & Server.MapPath("/dev/students.mdb")
MyAccount.Open(ConnStr)

CurUserMail = MyAccount.execute("select email from access where email = '" & Your_Email & "'")(0)

SQLtemp = "SELECT * FROM messages, access WHERE access.email = messages.email_from AND messages.ID = " & Request.QueryString("MessageID") & " AND messages.email_to = '" & Request.Cookies("email_to") & "' AND messages.data_entry = messages.data_entry"
Set rs = MyAccount.execute(SQLtemp)

'Response.Write "MessageID: " & Request.QueryString("MessageID") & "<br/>"
'    Response.Write "Email_to: " & Request.Cookies("email_to") & "<br/>"
'      Response.Write "Email_from:" & Request.Cookies("email_from") & "<br/>"
'      Response.Write "Message:" & Request.Cookies("message") & "<br/>"
'    Response.Flush

while not rs.eof

If Request.Cookies("email_to") = rs("email_to") Then

      Response.Write "<table align=""center""  cellpadding=""0"" cellspacing=""0"">" &_
                  "<tr><td width=""144"">" &_
                  "<p style=""margin-bottom:0px"">" &_
                  "<img src=""/dev/images/spacer.png"" width=""144"" height=""44"" class=""trans_header_2"" alt=""The College Mates"">" &_
                  "</p>" &_
                  "</td><td valign=""baseline"">" &_
                  "<p style=""margin-bottom:0px"">" &_
                  "<img src=""/dev/images/spacer.png"" width=""575"" height=""30"" class=""trans_header_3"" alt=""The College Mates"">" &_
                  "</p>" &_
                  "</td></tr>" &_
                  "<tr><td bgcolor=""#E27772"" align=""left"" colspan=""2"">" &_
                  "<p style=""margin-left:8px; margin-top:3px; margin-bottom:3px"">" &_
                  "<font color=""#F0F0F0""><strong>Welcome " & Your_FirstName & ", your representing " & Your_College & ", home of the " & Your_Mascot & "s!</strong></font>" &_
                  "</p>" &_
                  "</td></tr>" &_
                  "<tr><td colspan=""2"">" &_
                  "<table width=""100%""  cellpadding=""0"" cellspacing=""0"">" &_
                  "<tr><td width=""144"" align=""left"" valign=""top"">" &_
                  "<table width=""100%""  cellpadding=""0"" cellspacing=""0"" width=""168"" height=""155"" background=""/dev/images/spacer.png"" class=""trans_menu_bg_2"">" &_
                  "<tr><td valign=""top"">" &_
                  "<div style=""position:relative"">" &_
                  "<p style=""margin-left:10px; margin-top:10px; margin-bottom:10px; margin-right:10px"">" &_
                  "<a href=""/dev/protected.asp"">Your Profile</a><br>" &_
                  "<a href=""/dev/messages.asp"">Your Messages</a><br>" &_
                  "<a href="""">Link</a><br>" &_
                  "</p>" &_
                  "</div>" &_
                  "</td></tr>" &_
                  "</table>" &_
                  "</td><td valign=""top"" height=""235"" width=""575"" rowspan=""2"">" &_
                  "<table width=""100%"" cellpadding=""0"" cellspacing=""0"">" &_
                  "<tr><td bgcolor=""#999999"">" &_
                  "<h2>Your Message</h2>" &_
                  "</td></tr>" &_
                  "</table>" &_
                  "<table width=""575"" cellpadding=""0"" cellspacing=""0"" border=""1"" class=""messages_border"">" &_
                  "<tr><td>" &_
                  "<div style=""margin-left:9px; margin-right:9px; margin-top:9px; margin-bottom:9px"">" &_
                  "<table align=""center"" cellpadding=""0"" cellspacing=""0"" class=""message_border"" bordercolor=""#90b3e9"" border=""1"">" &_
                  "<tr><td>" &_
                  "<table width=""450"" cellpadding=""5"" cellspacing=""0"" bgcolor=""#EFEFEF"">" &_
                  "<tr><td colspan=""3"">Message from " & rs("firstname") & " " & rs("lastname") & " (" & rs("college") & ")</td></tr>" &_
                  "<tr><td width=""75"" height=""100"" rowspan=""4"">Picture goes here</td>" &_
                  "<td class=""message_td_font"" width=""65"">From:</td><td colspan=""3"">" & rs("email_from") & "</td></tr>" &_
                  "<tr><td class=""message_td_font"">Subject:</td><td colspan=""3"">" & rs("subject") & "</td></tr>" &_
                  "<tr><td class=""message_td_font"">Received:</td><td colspan=""3"">" & rs("data_entry") & "</td></tr>" &_
                  "<tr><td class=""message_td_font"">Message:</td><td colspan=""3"">" & lineBreak(rs("message"), 50, True) &  " </td></tr>" &_
                  "<tr><td>&nbsp;</td><td>&nbsp;</td><form action=""/dev/messages.asp"" method=""get""><td align=""right""><input type=""image"" src=""/dev/images/close_btn.png""></td>" &_
                  "</form>" &_
                  "<form action=""/dev/reply.asp"" method=""post"">" &_
                  "<td width=""55"" align=""center""><input type=""image"" src=""/dev/images/reply_btn.png""></td>" &_
                  "</form>" &_
                  "<form action=""/dev/deletemessage.asp"" method=""post"">" &_
                  "<td width=""55""><input type=""image"" src=""/dev/images/delete_btn.png"">" &_
                  "</td></tr>" &_
                  "</table>" &_
                  "</td></tr>" &_
                  "</table>" &_
                  "</div>" &_
                  "</td></tr>" &_
                  "</table>" &_
                  "<p style=""margin-top:10px; margin-left:0px"" align=""center"">" &_
                  "<font color=""#999999"" face=""arial"" size=""1px"">Developed and hosted by <a href=""http://www.brannongloverdesigns.com"" target=""_blank"">" &_
                  "<font color=""#999999"">Brannon Glover Designs</font></a>, 2006</font>" &_
                  "</p>"

End If
     
   rs.MoveNext
Wend



     
rs.Close
MyAccount.Close
set MyAccount = Nothing

%>
CyrexCore2k, are you able to userstand my code?
Yes but I don't see my function defined anywhere. Try
<% Dim MyAccount
Dim CurUserMail
Set MyAccount = Server.CreateObject("ADODB.Connection")
ConnStr = "DRIVER={Microsoft Access Driver (*.mdb)};pwd=password;"
ConnStr = ConnStr & "DBQ=" & Server.MapPath("/dev/students.mdb")
MyAccount.Open(ConnStr)

CurUserMail = MyAccount.execute("select email from access where email = '" & Your_Email & "'")(0)

SQLtemp = "SELECT * FROM messages, access WHERE access.email = messages.email_from AND messages.ID = " & Request.QueryString("MessageID") & " AND messages.email_to = '" & Request.Cookies("email_to") & "' AND messages.data_entry = messages.data_entry"
Set rs = MyAccount.execute(SQLtemp)

'Response.Write "MessageID: " & Request.QueryString("MessageID") & "<br/>"
'    Response.Write "Email_to: " & Request.Cookies("email_to") & "<br/>"
'     Response.Write "Email_from:" & Request.Cookies("email_from") & "<br/>"
'     Response.Write "Message:" & Request.Cookies("message") & "<br/>"
'    Response.Flush

while not rs.eof

If Request.Cookies("email_to") = rs("email_to") Then

     Response.Write "<table align=""center""  cellpadding=""0"" cellspacing=""0"">" &_
               "<tr><td width=""144"">" &_
               "<p style=""margin-bottom:0px"">" &_
               "<img src=""/dev/images/spacer.png"" width=""144"" height=""44"" class=""trans_header_2"" alt=""The College Mates"">" &_
               "</p>" &_
               "</td><td valign=""baseline"">" &_
               "<p style=""margin-bottom:0px"">" &_
               "<img src=""/dev/images/spacer.png"" width=""575"" height=""30"" class=""trans_header_3"" alt=""The College Mates"">" &_
               "</p>" &_
               "</td></tr>" &_
               "<tr><td bgcolor=""#E27772"" align=""left"" colspan=""2"">" &_
               "<p style=""margin-left:8px; margin-top:3px; margin-bottom:3px"">" &_
               "<font color=""#F0F0F0""><strong>Welcome " & Your_FirstName & ", your representing " & Your_College & ", home of the " & Your_Mascot & "s!</strong></font>" &_
               "</p>" &_
               "</td></tr>" &_
               "<tr><td colspan=""2"">" &_
               "<table width=""100%""  cellpadding=""0"" cellspacing=""0"">" &_
               "<tr><td width=""144"" align=""left"" valign=""top"">" &_
               "<table width=""100%""  cellpadding=""0"" cellspacing=""0"" width=""168"" height=""155"" background=""/dev/images/spacer.png"" class=""trans_menu_bg_2"">" &_
               "<tr><td valign=""top"">" &_
               "<div style=""position:relative"">" &_
               "<p style=""margin-left:10px; margin-top:10px; margin-bottom:10px; margin-right:10px"">" &_
               "<a href=""/dev/protected.asp"">Your Profile</a><br>" &_
               "<a href=""/dev/messages.asp"">Your Messages</a><br>" &_
               "<a href="""">Link</a><br>" &_
               "</p>" &_
               "</div>" &_
               "</td></tr>" &_
               "</table>" &_
               "</td><td valign=""top"" height=""235"" width=""575"" rowspan=""2"">" &_
               "<table width=""100%"" cellpadding=""0"" cellspacing=""0"">" &_
               "<tr><td bgcolor=""#999999"">" &_
               "<h2>Your Message</h2>" &_
               "</td></tr>" &_
               "</table>" &_
               "<table width=""575"" cellpadding=""0"" cellspacing=""0"" border=""1"" class=""messages_border"">" &_
               "<tr><td>" &_
               "<div style=""margin-left:9px; margin-right:9px; margin-top:9px; margin-bottom:9px"">" &_
               "<table align=""center"" cellpadding=""0"" cellspacing=""0"" class=""message_border"" bordercolor=""#90b3e9"" border=""1"">" &_
               "<tr><td>" &_
               "<table width=""450"" cellpadding=""5"" cellspacing=""0"" bgcolor=""#EFEFEF"">" &_
               "<tr><td colspan=""3"">Message from " & rs("firstname") & " " & rs("lastname") & " (" & rs("college") & ")</td></tr>" &_
               "<tr><td width=""75"" height=""100"" rowspan=""4"">Picture goes here</td>" &_
               "<td class=""message_td_font"" width=""65"">From:</td><td colspan=""3"">" & rs("email_from") & "</td></tr>" &_
               "<tr><td class=""message_td_font"">Subject:</td><td colspan=""3"">" & rs("subject") & "</td></tr>" &_
               "<tr><td class=""message_td_font"">Received:</td><td colspan=""3"">" & rs("data_entry") & "</td></tr>" &_
               "<tr><td class=""message_td_font"">Message:</td><td colspan=""3"">" & lineBreak(rs("message"), 50, True) &  " </td></tr>" &_
               "<tr><td>&nbsp;</td><td>&nbsp;</td><form action=""/dev/messages.asp"" method=""get""><td align=""right""><input type=""image"" src=""/dev/images/close_btn.png""></td>" &_
               "</form>" &_
               "<form action=""/dev/reply.asp"" method=""post"">" &_
               "<td width=""55"" align=""center""><input type=""image"" src=""/dev/images/reply_btn.png""></td>" &_
               "</form>" &_
               "<form action=""/dev/deletemessage.asp"" method=""post"">" &_
               "<td width=""55""><input type=""image"" src=""/dev/images/delete_btn.png"">" &_
               "</td></tr>" &_
               "</table>" &_
               "</td></tr>" &_
               "</table>" &_
               "</div>" &_
               "</td></tr>" &_
               "</table>" &_
               "<p style=""margin-top:10px; margin-left:0px"" align=""center"">" &_
               "<font color=""#999999"" face=""arial"" size=""1px"">Developed and hosted by <a href=""http://www.brannongloverdesigns.com"" target=""_blank"">" &_
               "<font color=""#999999"">Brannon Glover Designs</font></a>, 2006</font>" &_
               "</p>"

End If
     
   rs.MoveNext
Wend



     
rs.Close
MyAccount.Close
set MyAccount = Nothing

Function lineBreak(text, lineLength, forceBreaks)
     Dim x, i, vbCrLf
     vbCrLf = Chr(13) & Chr(10)
     lineBreak = ""
     Do
          For x = 1 To Len(text)
               If Mid(text, x, 2) = vbCrLf Then
                     lineBreak = lineBreak & Left(text, x - 1) & vbCrLf
                     If Len(text) > x + 2 Then
                          text = Mid(text, x + 2)
                     Else
                          text = ""
                     End If
                     Exit For
               ElseIf x = lineLength Then
                    If forceBreaks Then
                         lineBreak = lineBreak & Left(text, x) & vbCrLf
                         If Len(text) >= x + 1 Then
                              text = Mid(text, x + 1)
                         Else
                              text = ""
                         End If
                         Exit For
                    Else
                         For i = x To 1 Step -1
                              If Mid(text, i, 1) = " " Then
                                   Exit For
                              End If
                         Next
                         If Mid(text, i, 1) = " " Then
                              lineBreak = lineBreak & Left(text, i) & vbCrLf
                              If Len(text) >= i + 1 Then
                                   text = Mid(text, i + 1)
                              Else
                                   text = ""
                              End If
                         Else
                              lineBreak = lineBreak & Left(text, x) & vbCrLf
                              If Len(text) >= x + 1 Then
                                   text = Mid(text, x + 1)
                              Else
                                   text = ""
                              End If
                         End If
                         Exit For
                    End If
               End If
          Next
          If Len(text) <= lineLength Then
               lineBreak = lineBreak & text & vbCrLf
               text = ""
          End If
     Loop Until text = ""
End Function
%>

And see if that works for you.
Try this:

<%
'Example
'intLength = 100
'strString = TrimString(strString, intLength)

Function TrimString(strString, intLength)
  strString = Replace(strString, vbCrLf, "")
  If Len(strString) > intLength Then
    strString = Left(strString, intLength)
    aryString = Split(strString, " ")
    strString = ""
    For a = 0 to UBound(aryString)-1
      strString = strString & " " & aryString(a)
    Next
    strString = Trim(strString)
    strString = strString & ""
  End If
  TrimString = strString
End Function%>
Well the page comes up now, but the only problem is the message cell is blank.  I tried sending another message to myself, but still it's blank.  Any reason why?
scanet, do I place that by itself and it takes care of everything, or do I need to place something with my rs("message") code?
Try this:

replace(rs("message"), VbCr, "<BR>")

This line of code shows the line breaks made by the person who wrote the email.
zeybrandt, what if they don't make any linebreaks.  I don't wan them to have to physically make like breaks when writing a message.  I jus don't want it to span across the whole screen causing all of the cells to go out of whack.
here's something I've been playing around with. It does what you want the 1st time. What we need to figure out is how to apply this to subsequent lines. Obviously, you'd replace my "dummy" copy for strText with rs("message")


<%
dim strText, strMidChars
strText = "this is some text to see how I can break a line in the middle at a certain character position"

strMidChars = left(strText,instrrev(strText," ",25)) & "<br>" & right(strText,len(strText) - instrrev(strText," ",25))

response.write strText & "<br><br>"
response.write strMidChars & "<br><br>"
%>
shadie,

don't you think it is just a question of how the tables are constructed? Is there a need for the code of yours (thought, it is quite elegant).
please refer back to my original comments. I thought the simple solution for this all along was to set the absolute size of the tables and cells in question.

pingeyeg, to an earlier response of yours:

You're concerned about setting the width in the "wrong cell", why not make sure that any cell that lines up against the rs("Message") cell is also set to 500, or whatever that magic number is?
CyrexCore2k, that didn't help help the solution.  I'm still getting nothing in the message column.
It would be:

intLength = 100 'maximum length of sentince before code makes new line
strString = TrimString(rs("message"), intLength)
scanet, for some reason it doesn't like the rs in your code.  Why would that be?
CyrexCore2k, I have your code on my page, but for some reason I am not able to view the rs("message") field.  Nothing shows up there now.  Any reason why?
Well I've tested out that function and it works fine for me... I'm not really sure what could cause it to just be empty suddenly.
CyrexCore2k, just for grins and giggle, would you mind looking a my code again?  Maybe I messed something up that would fix it.

<%@ Language=VBScript %>

<%Response.Expires = -1 %>
<%Response.ExpiresAbsolute = Now() - 1 %>
<%Response.AddHeader "pragma", "no-cache" %>
<%Response.AddHeader "cache-control", "private" %>
<%Response.CacheControl = "no-cache" %>
 
<%
Response.Expires = -1000
Response.Buffer = True
Response.Clear
%>

<!--#include file="logincheck.asp"-->

<html>
<head>
<title>Welcome <%= Your_FirstName%> to The CollegeMates</title>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" type="text/css" href="/dev/style.css">
<script language=JavaScript>
<!--
var message="";
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")
// -->
</script>
</head>

<body bgcolor="#FFFFFF" topmargin="5">

<% Dim MyAccount
Set MyAccount = Server.CreateObject("ADODB.Connection")
ConnStr = "DRIVER={Microsoft Access Driver (*.mdb)};pwd=password;"
ConnStr = ConnStr & "DBQ=" & Server.MapPath("/dev/students.mdb")
MyAccount.Open(ConnStr)

SQLtemp = "SELECT * FROM messages, access, myimages WHERE access.email = messages.email_from AND messages.ID = " & Request.QueryString("MessageID") & " AND messages.email_to = '" & Request.Cookies("email_to") & "'"
Set rs = MyAccount.execute(SQLtemp)

'Response.Write "MessageID: " & Request.QueryString("MessageID") & "<br/>"
'    Response.Write "Email_to: " & Request.Cookies("email_to") & "<br/>"
'     Response.Write "Email_from:" & Request.Cookies("email_from") & "<br/>"
'     Response.Write "Message:" & Request.Cookies("message") & "<br/>"
'    Response.Flush

while not rs.eof

If Request.Cookies("email_to") = rs("email_to") Then

     Response.Write "<table align=""center""  cellpadding=""0"" cellspacing=""0"">" &_
               "<tr><td width=""144"">" &_
               "<p style=""margin-bottom:0px"">" &_
               "<img src=""/dev/images/spacer.png"" width=""144"" height=""44"" class=""trans_header_2"" alt=""The College Mates"">" &_
               "</p>" &_
               "</td><td valign=""bottom"">" &_
               "<p style=""margin-bottom:0px"">" &_
               "<img src=""/dev/images/spacer.png"" width=""575"" height=""30"" class=""trans_header_3"" alt=""The College Mates"">" &_
               "</p>" &_
               "</td></tr>" &_
               "<tr><td bgcolor=""#E27772"" align=""left"" colspan=""2"">" &_
               "<p style=""margin-left:8px; margin-top:3px; margin-bottom:3px"">" &_
               "<font color=""#F0F0F0""><strong>Welcome " & Your_FirstName & ", your representing " & Your_College & ", home of the " & Your_Mascot & "s!</strong></font>" &_
               "</p>" &_
               "</td></tr>" &_
               "<tr><td colspan=""2"">" &_
               "<table width=""100%""  cellpadding=""0"" cellspacing=""0"">" &_
               "<tr><td width=""144"" align=""left"" valign=""top"">" &_
               "<table width=""100%""  cellpadding=""0"" cellspacing=""0"" width=""168"" height=""155"" background=""/dev/images/spacer.png"" class=""trans_menu_bg_2"">" &_
               "<tr><td valign=""top"">" &_
               "<div style=""position:relative"">" &_
               "<p style=""margin-left:10px; margin-top:10px; margin-bottom:10px; margin-right:10px"">" &_
               "<a href=""/dev/protected.asp"">Your Profile</a><br>" &_
               "<a href=""/dev/messages.asp"">Your Messages</a><br>" &_
               "<a href="""">Link</a><br>" &_
               "</p>" &_
               "</div>" &_
               "</td></tr>" &_
               "</table>" &_
               "</td><td valign=""top"" height=""235"" width=""575"" rowspan=""2"">" &_
               "<table width=""100%"" cellpadding=""0"" cellspacing=""0"">" &_
               "<tr><td bgcolor=""#999999"">" &_
               "<h2>Your Message</h2>" &_
               "</td></tr>" &_
               "</table>" &_
               "<table width=""575"" cellpadding=""0"" cellspacing=""0"" class=""global_border"">" &_
               "<tr><td>" &_
               "<div style=""margin-left:9px; margin-right:9px; margin-top:9px; margin-bottom:9px"">" &_
               "<table align=""center"" cellpadding=""0"" cellspacing=""0"" class=""message_border"" bordercolor=""#90b3e9"" border=""1"">" &_
               "<tr><td>" &_
               "<table width=""450"" cellpadding=""5"" cellspacing=""0"" bgcolor=""#EFEFEF"">" &_
               "<tr><td colspan=""5"">Message from " & rs("firstname") & " " & rs("lastname") & " (" & rs("college") & ")</td></tr>" &_
               "<tr><td width=""75"" valign=""top"" rowspan=""4""><IMG width=""75"" SRC='/dev/download.asp?id=" & rs("id") & "'></td>" &_
               "<td class=""message_td_font"" width=""65"">From:</td><td colspan=""3"" width=""300"">" & rs("email_from") & "</td></tr>" &_
               "<tr><td class=""message_td_font"">Subject:</td><td colspan=""3"" width=""300"">" & rs("subject") & "</td></tr>" &_
               "<tr><td class=""message_td_font"">Received:</td><td colspan=""3"" width=""300"">" & rs("data_entry") & "</td></tr>" &_
               "<tr><td class=""message_td_font"">Message:</td><td colspan=""3"">" & lineBreak(rs("message"), 50, True) &  " </td></tr>" &_
               "<tr><td>&nbsp;</td><td>&nbsp;</td><form action=""/dev/messages.asp"" method=""get""><td align=""right""><input type=""image"" src=""/dev/images/close_btn.png""></td>" &_
               "</form>" &_
               "<form action='/dev/reply.asp?MessageID=" & rs("ID") & "' method=""post"">" &_
               "<td width=""55"" align=""center""><input type=""image"" src=""/dev/images/reply_btn.png""></td>" &_
               "</form>" &_
               "<form action='/dev/deletemessage.asp?MessageID=" & rs("ID") & "' method=""post"">" &_
                     "<td width=""55""><input type=""image"" src=""/dev/images/delete_btn.png"">" &_
                     "</td></form></tr>" &_
               "</table>" &_
               "</td></tr>" &_
               "</table>" &_
               "</div>" &_
               "</td></tr>" &_
               "</table>" &_
               "<p style=""margin-top:10px; margin-left:0px"" align=""center"">" &_
               "<font color=""#999999"" face=""arial"" size=""1px"">Developed and hosted by <a href=""http://www.brannongloverdesigns.com"" target=""_blank"">" &_
               "<font color=""#999999"">Brannon Glover Designs</font></a>, 2006</font>" &_
               "</p>"

End If
     
   rs.MoveNext
Wend



     
rs.Close
MyAccount.Close
set MyAccount = Nothing

Function lineBreak(text, lineLength, forceBreaks)
     Dim x, i, vbCrLf
     vbCrLf = Chr(13) & Chr(10)
     lineBreak = ""
     Do
          For x = 1 To Len(text)
               If Mid(text, x, 2) = vbCrLf Then
                     lineBreak = lineBreak & Left(text, x - 1) & vbCrLf
                     If Len(text) > x + 2 Then
                          text = Mid(text, x + 2)
                     Else
                          text = ""
                     End If
                     Exit For
               ElseIf x = lineLength Then
                    If forceBreaks Then
                         lineBreak = lineBreak & Left(text, x) & vbCrLf
                         If Len(text) >= x + 1 Then
                              text = Mid(text, x + 1)
                         Else
                              text = ""
                         End If
                         Exit For
                    Else
                         For i = x To 1 Step -1
                              If Mid(text, i, 1) = " " Then
                                   Exit For
                              End If
                         Next
                         If Mid(text, i, 1) = " " Then
                              lineBreak = lineBreak & Left(text, i) & vbCrLf
                              If Len(text) >= i + 1 Then
                                   text = Mid(text, i + 1)
                              Else
                                   text = ""
                              End If
                         Else
                              lineBreak = lineBreak & Left(text, x) & vbCrLf
                              If Len(text) >= x + 1 Then
                                   text = Mid(text, x + 1)
                              Else
                                   text = ""
                              End If
                         End If
                         Exit For
                    End If
               End If
          Next
          If Len(text) <= lineLength Then
               lineBreak = lineBreak & text & vbCrLf
               text = ""
          End If
     Loop Until text = ""
End Function
%>
pingeyeg, you have to look closer at the function that CyrexCore2k gave you. The variable "text" is referenced throughout the function. You will need to declare your rs("message") = to text to get it to work. Also, I was playing around with this function. It's really pretty neat! I was not able to get it to work though until I swapped out all instances of vbCrLf with "<br>", then it started working. And one more thing, given the nature of what the function is trying to do, I can see that it is trying to not break any lines in the middle of a word... but it does. There may be a typo in one of the if/then's
let me further qualify something. I said you need to replace all instances of vbCrLf -- this is not true. I only changed the ones where you set lineBreak = lineBreak & ...

Where you're checking to see if Mid(text, x, 2) = vbCrLf (for example), you can leave those alone
shadie, I appreciate the info.  Now just to make sure I understand you correctly I should place rs("message") = text?

Meaning, text = "rs("message")"

Is this what you mean.
ASKER CERTIFIED SOLUTION
Avatar of CyrexCore2k
CyrexCore2k
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works wonderfully now!  Thanks!
shadie i realized that you're right about needing the "<br>" in there. the easiest solution though is just put

lineBreak = replace(lineBreak, vbCrLf, "<br>")

as the last line of the function.

Also you'll need to set the forcebreaks flag to false if you don't want it to break words. Either way however it _will_ break words longer than the max length.
where would you mod. this function to insert a "-" on the words it's breaking longer than maxLength
See if this works

Function lineBreak(text, lineLength, forceBreaks)
     Dim x, i, vbCrLf
     vbCrLf = Chr(13) & Chr(10)
     lineBreak = ""
     Do
          For x = 1 To Len(text)
               If Mid(text, x, 2) = vbCrLf Then
                     lineBreak = lineBreak & Left(text, x - 1) & vbCrLf
                     If Len(text) > x + 2 Then
                          text = Mid(text, x + 2)
                     Else
                          text = ""
                     End If
                     Exit For
               ElseIf x = lineLength Then
                    If forceBreaks Then
                         lineBreak = lineBreak & Left(text, x - 1) & "-" & vbCrLf
                         text = Mid(text, x)
                         Exit For
                    Else
                         For i = x To 1 Step -1
                              If Mid(text, i, 1) = " " Then
                                   Exit For
                              End If
                         Next
                         If Mid(text, i, 1) = " " Then
                              lineBreak = lineBreak & Left(text, i) & vbCrLf
                              If Len(text) >= i + 1 Then
                                   text = Mid(text, i + 1)
                              Else
                                   text = ""
                              End If
                         Else
                              lineBreak = lineBreak & Left(text, x) & vbCrLf
                              If Len(text) >= x + 1 Then
                                   text = Mid(text, x + 1)
                              Else
                                   text = ""
                              End If
                         End If
                         Exit For
                    End If
               End If
          Next
          If Len(text) <= lineLength Then
               lineBreak = lineBreak & text & vbCrLf
               text = ""
          End If
     Loop Until text = ""
End Function
yup, it does, though it also puts a "-" on the non-breaking words too. But it should be easily adaptable to check for a space and only insert "-" where it's not replacing the space. Thanks for the second look!