Ask a Question related to ASP Database, Design and Development.
-
raj #1
text wrap problems...
Hi, ive got this script for aspin.com that wraps text to a specified
no of characters. Only problem is, it doesnt account for line breaks
(so any shorter lines dont get a vbCrLf and the alignment is messed up
further down the line) Can anyone help with this. Cheers
Function WordWrap(strTextToBeWrapped, intMaxLineLength)
Dim strWrappedText ' Result storage
Dim intLengthOfInput ' Length of original
Dim intCurrentPosition ' Where we're at now
Dim intCurrentLineStart ' Where the current line starts
Dim intPositionOfLastSpace ' Last space we saw
Dim strTempText
intLengthOfInput = Len(strTextToBeWrapped)
' Start both of these at the beginning
intCurrentPosition = 1
intCurrentLineStart = 1
' Loop through until we get to the end
Do While intCurrentPosition < intLengthOfInput
' If the current position is a space, make a note of
' it's location for later use.
If Mid(strTextToBeWrapped, intCurrentPosition, 1) = " " Then
intPositionOfLastSpace = intCurrentPosition
End If
' If we're at what should be the end of a line, we go back
' to the last space we saw and cut the line there.
If intCurrentPosition = intCurrentLineStart + intMaxLineLength Then
' Some debugging lines if something's not lining up.
' Response.Write intCurrentLineStart & "<br/>"
' Response.Write intPositionOfLastSpace & "<br/>"
' Response.Write Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
intPositionOfLastSpace - intCurrentLineStart + 1)) & "<br/>"
' Append this latest line to our result
response.Write "linebreak at= " & intCurrentLineStart & "<BR>"
strTempText = Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
intPositionOfLastSpace - intCurrentLineStart + 1))
strWrappedText = strWrappedText & strTempText & "^" & vbCrLf
' Reset the next line's starting point to the point we
' used for the last one's end + 1.
intCurrentLineStart = intPositionOfLastSpace + 1
' Remove any leading spaces that might mess up our
' character count. If you want to just pull of one,
' switch this to a simple If conditional instead of
' looping.
Do While Mid(strTextToBeWrapped, intCurrentLineStart, 1) = " "
intCurrentLineStart = intCurrentLineStart + 1
Loop
End If
intCurrentPosition = intCurrentPosition + 1
Loop
' Since the loop ends before we add the remaining text,
' add remaining text as the last line.
strWrappedText = strWrappedText & Trim(Mid(strTextToBeWrapped,
intcurrentLineStart)) & vbCrLf
WordWrap = strWrappedText
End Function
raj Guest
-
Text wrap adding a ghost Wrap???
hello, I was working on creating a clipping mask on a photo by using the pen tool and making a silo. Then I would cut the picture and paste into... -
Wrap Text
I was able to accomplish wrapping the text by grouping the picture and text in a text box - worked perfectly. "vivian" <vivian.n@suothisd.org>... -
InDesign Text Wrap and Position problems
After opening PageMaker 6.5 files in InDesign, I experienced two text problems with parallel columns of text that previously had lined up precisely.... -
Text wrap in CS
Greetings, While trying to use the text wrap feature in AI CS, I encountered a peculiar problem. It seems that AI will attempt the text wrap, but... -
Text Wrap around an image pasted into a text box
This is an imperfect workaround, but I use it quite a bit. Paste your graphic in-line, followed by a hair-space or thin-space. Then format your... -
McKirahan #2
Re: text wrap problems...
"raj" <karwalr@hotmail.com> wrote in message
news:477bcb83.0312150417.470a31c7@posting.google.c om...> Hi, ive got this script for aspin.com that wraps text to a specified
> no of characters. Only problem is, it doesnt account for line breaks
> (so any shorter lines dont get a vbCrLf and the alignment is messed up
> further down the line) Can anyone help with this. Cheers
>
> Function WordWrap(strTextToBeWrapped, intMaxLineLength)
> Dim strWrappedText ' Result storage
> Dim intLengthOfInput ' Length of original
> Dim intCurrentPosition ' Where we're at now
> Dim intCurrentLineStart ' Where the current line starts
> Dim intPositionOfLastSpace ' Last space we saw
> Dim strTempText
>
> intLengthOfInput = Len(strTextToBeWrapped)
>
> ' Start both of these at the beginning
> intCurrentPosition = 1
> intCurrentLineStart = 1
>
> ' Loop through until we get to the end
> Do While intCurrentPosition < intLengthOfInput
> ' If the current position is a space, make a note of
> ' it's location for later use.
>
> If Mid(strTextToBeWrapped, intCurrentPosition, 1) = " " Then
> intPositionOfLastSpace = intCurrentPosition
> End If
>
> ' If we're at what should be the end of a line, we go back
> ' to the last space we saw and cut the line there.
> If intCurrentPosition = intCurrentLineStart + intMaxLineLength Then
> ' Some debugging lines if something's not lining up.
> ' Response.Write intCurrentLineStart & "<br/>"
> ' Response.Write intPositionOfLastSpace & "<br/>"
> ' Response.Write Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
> intPositionOfLastSpace - intCurrentLineStart + 1)) & "<br/>"
>
> ' Append this latest line to our result
>
> response.Write "linebreak at= " & intCurrentLineStart & "<BR>"
>
> strTempText = Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
> intPositionOfLastSpace - intCurrentLineStart + 1))
> strWrappedText = strWrappedText & strTempText & "^" & vbCrLf
>
> ' Reset the next line's starting point to the point we
> ' used for the last one's end + 1.
> intCurrentLineStart = intPositionOfLastSpace + 1
>
> ' Remove any leading spaces that might mess up our
> ' character count. If you want to just pull of one,
> ' switch this to a simple If conditional instead of
> ' looping.
> Do While Mid(strTextToBeWrapped, intCurrentLineStart, 1) = " "
> intCurrentLineStart = intCurrentLineStart + 1
> Loop
> End If
>
> intCurrentPosition = intCurrentPosition + 1
> Loop
>
> ' Since the loop ends before we add the remaining text,
> ' add remaining text as the last line.
> strWrappedText = strWrappedText & Trim(Mid(strTextToBeWrapped,
> intcurrentLineStart)) & vbCrLf
>
> WordWrap = strWrappedText
> End Function
Which of these do you want?
1) "strTextToBeWrapped" will contain vbCrLf's that you want ignored;
If so then try:
strTextToBeWrapped = Replace(strTextToBeWrapped,vbCrLf," ")
2) "WordWrap()" should only process portions of "strTextToBeWrapped"
between vbCrLf's;
If so then try:
strTextToBeWrapped = Replace(strTextToBeWrapped,vbCrLf,"<br>")
strTextToBeWrappedNow = Split(strTextToBeWrapped,"<br>")
For i = 0 To UBound(strTextToBeWrappedNow)
If strTextToBeWrappedNow(i) <> "" Then
Call WordWrap(strTextToBeWrappedNow(i), intMaxLineLength)
End If
Next
McKirahan Guest
-
raj #3
Re: text wrap problems...
i see what u mean but still no luck. Heres an example of what is
happening. The ^ character indicates where its puttin the break in...
->
mysite.com JOBNEWS
[url]http://www.mysite.com[/url]
^
-------------------------------------------------------------------
Dear^
[EMAIL_TO]
16/12/2003
Issue No: 1
Welcome to the Job Seekers bulletin.
^
There are 653 supply teachers currently registered with on the Surrey
Supply^
<-
As you can see, its not putting in a break after JOBNEWS as it should
as the line is less that the set char length (80). Heres my full
version of the script...cant seem to make it bloody work!!
strText = "MY TEXT HERE
Do While InStr(strText, " ") > 0
strText = Replace(strText, " ", " ")
Loop
strText = Replace(strText, vbCrLf, "# ")
strTextWrap = WordWrap(strText, 80)
out = out & AddBrToCrLf(strTextWrap)
Function WordWrap(strTextToBeWrapped, intMaxLineLength)
Dim strWrappedText ' Result storage
Dim intLengthOfInput ' Length of original
Dim intCurrentPosition ' Where we're at now
Dim intCurrentLineStart ' Where the current line starts
Dim intPositionOfLastSpace ' Last space we saw
Dim strTempText
intLengthOfInput = Len(strTextToBeWrapped)
' Start both of these at the beginning
intCurrentPosition = 1
intCurrentLineStart = 1
' Loop through until we get to the end
Do While intCurrentPosition < intLengthOfInput
' If the current position is a space, make a note of
' it's location for later use.
If Mid(strTextToBeWrapped, intCurrentPosition, 1) = " " Then
intPositionOfLastSpace = intCurrentPosition
End If
' If we're at what should be the end of a line, we go back
' to the last space we saw and cut the line there.
If intCurrentPosition = intCurrentLineStart + intMaxLineLength Then
' Some debugging lines if something's not lining up.
' Response.Write intCurrentLineStart & "<br/>"
' Response.Write intPositionOfLastSpace & "<br/>"
' Response.Write Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
intPositionOfLastSpace - intCurrentLineStart + 1)) & "<br/>"
' Append this latest line to our result
' response.Write Right(strWrappedText,4) & "<BR>"
' response.Write "linebreak at= " & intCurrentLineStart & "<BR>"
strTempText = Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
intPositionOfLastSpace - intCurrentLineStart + 1))
strWrappedText = strWrappedText & strTempText & "^" & vbCrLf
' Reset the next line's starting point to the point we
' used for the last one's end + 1.
intCurrentLineStart = intPositionOfLastSpace + 1
' Remove any leading spaces that might mess up our
' character count. If you want to just pull of one,
' switch this to a simple If conditional instead of
' looping.
Do While Mid(strTextToBeWrapped, intCurrentLineStart, 1) = " "
intCurrentLineStart = intCurrentLineStart + 1
Loop
End If
intCurrentPosition = intCurrentPosition + 1
Loop
' Since the loop ends before we add the remaining text,
' add remaining text as the last line.
strWrappedText = strWrappedText & Trim(Mid(strTextToBeWrapped,
intcurrentLineStart)) & vbCrLf
WordWrap = strWrappedText
End Function
Function AddBrToCrLf(strInput)
strInput = Replace(strInput, vbCrLf, "<br>" & vbCrLf)
AddBrToCrLf = Replace(strInput, "#", "<br>" & vbCrLf)
End Function
"McKirahan" <News@McKirahan.com> wrote in message news:<criDb.559080$Fm2.526151@attbi_s04>...> "raj" <karwalr@hotmail.com> wrote in message
> news:477bcb83.0312150417.470a31c7@posting.google.c om...>> > Hi, ive got this script for aspin.com that wraps text to a specified
> > no of characters. Only problem is, it doesnt account for line breaks
> > (so any shorter lines dont get a vbCrLf and the alignment is messed up
> > further down the line) Can anyone help with this. Cheers
> >
> > Function WordWrap(strTextToBeWrapped, intMaxLineLength)
> > Dim strWrappedText ' Result storage
> > Dim intLengthOfInput ' Length of original
> > Dim intCurrentPosition ' Where we're at now
> > Dim intCurrentLineStart ' Where the current line starts
> > Dim intPositionOfLastSpace ' Last space we saw
> > Dim strTempText
> >
> > intLengthOfInput = Len(strTextToBeWrapped)
> >
> > ' Start both of these at the beginning
> > intCurrentPosition = 1
> > intCurrentLineStart = 1
> >
> > ' Loop through until we get to the end
> > Do While intCurrentPosition < intLengthOfInput
> > ' If the current position is a space, make a note of
> > ' it's location for later use.
> >
> > If Mid(strTextToBeWrapped, intCurrentPosition, 1) = " " Then
> > intPositionOfLastSpace = intCurrentPosition
> > End If
> >
> > ' If we're at what should be the end of a line, we go back
> > ' to the last space we saw and cut the line there.
> > If intCurrentPosition = intCurrentLineStart + intMaxLineLength Then
> > ' Some debugging lines if something's not lining up.
> > ' Response.Write intCurrentLineStart & "<br/>"
> > ' Response.Write intPositionOfLastSpace & "<br/>"
> > ' Response.Write Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
> > intPositionOfLastSpace - intCurrentLineStart + 1)) & "<br/>"
> >
> > ' Append this latest line to our result
> >
> > response.Write "linebreak at= " & intCurrentLineStart & "<BR>"
> >
> > strTempText = Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
> > intPositionOfLastSpace - intCurrentLineStart + 1))
> > strWrappedText = strWrappedText & strTempText & "^" & vbCrLf
> >
> > ' Reset the next line's starting point to the point we
> > ' used for the last one's end + 1.
> > intCurrentLineStart = intPositionOfLastSpace + 1
> >
> > ' Remove any leading spaces that might mess up our
> > ' character count. If you want to just pull of one,
> > ' switch this to a simple If conditional instead of
> > ' looping.
> > Do While Mid(strTextToBeWrapped, intCurrentLineStart, 1) = " "
> > intCurrentLineStart = intCurrentLineStart + 1
> > Loop
> > End If
> >
> > intCurrentPosition = intCurrentPosition + 1
> > Loop
> >
> > ' Since the loop ends before we add the remaining text,
> > ' add remaining text as the last line.
> > strWrappedText = strWrappedText & Trim(Mid(strTextToBeWrapped,
> > intcurrentLineStart)) & vbCrLf
> >
> > WordWrap = strWrappedText
> > End Function
>
> Which of these do you want?
>
> 1) "strTextToBeWrapped" will contain vbCrLf's that you want ignored;
>
> If so then try:
>
> strTextToBeWrapped = Replace(strTextToBeWrapped,vbCrLf," ")
>
>
> 2) "WordWrap()" should only process portions of "strTextToBeWrapped"
> between vbCrLf's;
>
> If so then try:
>
> strTextToBeWrapped = Replace(strTextToBeWrapped,vbCrLf,"<br>")
> strTextToBeWrappedNow = Split(strTextToBeWrapped,"<br>")
> For i = 0 To UBound(strTextToBeWrappedNow)
> If strTextToBeWrappedNow(i) <> "" Then
> Call WordWrap(strTextToBeWrappedNow(i), intMaxLineLength)
> End If
> Nextraj Guest
-
McKirahan #4
Re: text wrap problems...
"raj" <karwalr@hotmail.com> wrote in message
news:477bcb83.0312160129.539a8b36@posting.google.c om...news:<criDb.559080$Fm2.526151@attbi_s04>...> i see what u mean but still no luck. Heres an example of what is
> happening. The ^ character indicates where its puttin the break in...
>
>
>
> ->
> mysite.com JOBNEWS
> [url]http://www.mysite.com[/url]
> ^
> -------------------------------------------------------------------
> Dear^
> [EMAIL_TO]
> 16/12/2003
> Issue No: 1
>
> Welcome to the Job Seekers bulletin.
> ^
> There are 653 supply teachers currently registered with on the Surrey
> Supply^
> <-
>
> As you can see, its not putting in a break after JOBNEWS as it should
> as the line is less that the set char length (80). Heres my full
> version of the script...cant seem to make it bloody work!!
>
> strText = "MY TEXT HERE
> Do While InStr(strText, " ") > 0
> strText = Replace(strText, " ", " ")
> Loop
> strText = Replace(strText, vbCrLf, "# ")
> strTextWrap = WordWrap(strText, 80)
>
> out = out & AddBrToCrLf(strTextWrap)
>
>
>
> Function WordWrap(strTextToBeWrapped, intMaxLineLength)
> Dim strWrappedText ' Result storage
> Dim intLengthOfInput ' Length of original
> Dim intCurrentPosition ' Where we're at now
> Dim intCurrentLineStart ' Where the current line starts
> Dim intPositionOfLastSpace ' Last space we saw
> Dim strTempText
>
> intLengthOfInput = Len(strTextToBeWrapped)
>
> ' Start both of these at the beginning
> intCurrentPosition = 1
> intCurrentLineStart = 1
>
> ' Loop through until we get to the end
> Do While intCurrentPosition < intLengthOfInput
> ' If the current position is a space, make a note of
> ' it's location for later use.
>
> If Mid(strTextToBeWrapped, intCurrentPosition, 1) = " " Then
> intPositionOfLastSpace = intCurrentPosition
> End If
>
> ' If we're at what should be the end of a line, we go back
> ' to the last space we saw and cut the line there.
> If intCurrentPosition = intCurrentLineStart + intMaxLineLength Then
> ' Some debugging lines if something's not lining up.
> ' Response.Write intCurrentLineStart & "<br/>"
> ' Response.Write intPositionOfLastSpace & "<br/>"
> ' Response.Write Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
> intPositionOfLastSpace - intCurrentLineStart + 1)) & "<br/>"
>
> ' Append this latest line to our result
>
> ' response.Write Right(strWrappedText,4) & "<BR>"
> ' response.Write "linebreak at= " & intCurrentLineStart & "<BR>"
>
> strTempText = Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
> intPositionOfLastSpace - intCurrentLineStart + 1))
> strWrappedText = strWrappedText & strTempText & "^" & vbCrLf
>
>
> ' Reset the next line's starting point to the point we
> ' used for the last one's end + 1.
> intCurrentLineStart = intPositionOfLastSpace + 1
>
> ' Remove any leading spaces that might mess up our
> ' character count. If you want to just pull of one,
> ' switch this to a simple If conditional instead of
> ' looping.
> Do While Mid(strTextToBeWrapped, intCurrentLineStart, 1) = " "
> intCurrentLineStart = intCurrentLineStart + 1
> Loop
> End If
>
> intCurrentPosition = intCurrentPosition + 1
> Loop
>
>
>
>
> ' Since the loop ends before we add the remaining text,
> ' add remaining text as the last line.
> strWrappedText = strWrappedText & Trim(Mid(strTextToBeWrapped,
> intcurrentLineStart)) & vbCrLf
>
> WordWrap = strWrappedText
> End Function
>
>
> Function AddBrToCrLf(strInput)
> strInput = Replace(strInput, vbCrLf, "<br>" & vbCrLf)
> AddBrToCrLf = Replace(strInput, "#", "<br>" & vbCrLf)
> End Function
>
>
>
>
> "McKirahan" <News@McKirahan.com> wrote in message> > "raj" <karwalr@hotmail.com> wrote in message
> > news:477bcb83.0312150417.470a31c7@posting.google.c om...> >> > > Hi, ive got this script for aspin.com that wraps text to a specified
> > > no of characters. Only problem is, it doesnt account for line breaks
> > > (so any shorter lines dont get a vbCrLf and the alignment is messed up
> > > further down the line) Can anyone help with this. Cheers
> > >
> > > Function WordWrap(strTextToBeWrapped, intMaxLineLength)
> > > Dim strWrappedText ' Result storage
> > > Dim intLengthOfInput ' Length of original
> > > Dim intCurrentPosition ' Where we're at now
> > > Dim intCurrentLineStart ' Where the current line starts
> > > Dim intPositionOfLastSpace ' Last space we saw
> > > Dim strTempText
> > >
> > > intLengthOfInput = Len(strTextToBeWrapped)
> > >
> > > ' Start both of these at the beginning
> > > intCurrentPosition = 1
> > > intCurrentLineStart = 1
> > >
> > > ' Loop through until we get to the end
> > > Do While intCurrentPosition < intLengthOfInput
> > > ' If the current position is a space, make a note of
> > > ' it's location for later use.
> > >
> > > If Mid(strTextToBeWrapped, intCurrentPosition, 1) = " " Then
> > > intPositionOfLastSpace = intCurrentPosition
> > > End If
> > >
> > > ' If we're at what should be the end of a line, we go back
> > > ' to the last space we saw and cut the line there.
> > > If intCurrentPosition = intCurrentLineStart + intMaxLineLength Then
> > > ' Some debugging lines if something's not lining up.
> > > ' Response.Write intCurrentLineStart & "<br/>"
> > > ' Response.Write intPositionOfLastSpace & "<br/>"
> > > ' Response.Write Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
> > > intPositionOfLastSpace - intCurrentLineStart + 1)) & "<br/>"
> > >
> > > ' Append this latest line to our result
> > >
> > > response.Write "linebreak at= " & intCurrentLineStart & "<BR>"
> > >
> > > strTempText = Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
> > > intPositionOfLastSpace - intCurrentLineStart + 1))
> > > strWrappedText = strWrappedText & strTempText & "^" & vbCrLf
> > >
> > > ' Reset the next line's starting point to the point we
> > > ' used for the last one's end + 1.
> > > intCurrentLineStart = intPositionOfLastSpace + 1
> > >
> > > ' Remove any leading spaces that might mess up our
> > > ' character count. If you want to just pull of one,
> > > ' switch this to a simple If conditional instead of
> > > ' looping.
> > > Do While Mid(strTextToBeWrapped, intCurrentLineStart, 1) = " "
> > > intCurrentLineStart = intCurrentLineStart + 1
> > > Loop
> > > End If
> > >
> > > intCurrentPosition = intCurrentPosition + 1
> > > Loop
> > >
> > > ' Since the loop ends before we add the remaining text,
> > > ' add remaining text as the last line.
> > > strWrappedText = strWrappedText & Trim(Mid(strTextToBeWrapped,
> > > intcurrentLineStart)) & vbCrLf
> > >
> > > WordWrap = strWrappedText
> > > End Function
> >
> > Which of these do you want?
> >
> > 1) "strTextToBeWrapped" will contain vbCrLf's that you want ignored;
> >
> > If so then try:
> >
> > strTextToBeWrapped = Replace(strTextToBeWrapped,vbCrLf," ")
> >
> >
> > 2) "WordWrap()" should only process portions of "strTextToBeWrapped"
> > between vbCrLf's;
> >
> > If so then try:
> >
> > strTextToBeWrapped = Replace(strTextToBeWrapped,vbCrLf,"<br>")
> > strTextToBeWrappedNow = Split(strTextToBeWrapped,"<br>")
> > For i = 0 To UBound(strTextToBeWrappedNow)
> > If strTextToBeWrappedNow(i) <> "" Then
> > Call WordWrap(strTextToBeWrappedNow(i), intMaxLineLength)
> > End If
> > Next
Where on "aspin.com" did you find this WordWrap function?
All I could fund was:
This is a function to provide word wrap capability in your ASP pages.
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=4&txtCodeId
=6220
I suspect that you're trying to pass in (to the function) the entire string
rather than a single line.
I wanted to read the function's documentation to better understand it --
though I'll probably rewrite it anyway.
Also, could your provide a statement of exactly what you're trying to do.
For example,
"I have a text file that I want reformatted so no single line exceeds 80
bytes."
McKirahan Guest
-
McKirahan #5
Re: text wrap problems...
"McKirahan" <News@McKirahan.com> wrote in message
news:ZuGDb.407540$ao4.1336315@attbi_s51...up> "raj" <karwalr@hotmail.com> wrote in message
> news:477bcb83.0312160129.539a8b36@posting.google.c om...> news:<criDb.559080$Fm2.526151@attbi_s04>...> > i see what u mean but still no luck. Heres an example of what is
> > happening. The ^ character indicates where its puttin the break in...
> >
> >
> >
> > ->
> > mysite.com JOBNEWS
> > [url]http://www.mysite.com[/url]
> > ^
> > -------------------------------------------------------------------
> > Dear^
> > [EMAIL_TO]
> > 16/12/2003
> > Issue No: 1
> >
> > Welcome to the Job Seekers bulletin.
> > ^
> > There are 653 supply teachers currently registered with on the Surrey
> > Supply^
> > <-
> >
> > As you can see, its not putting in a break after JOBNEWS as it should
> > as the line is less that the set char length (80). Heres my full
> > version of the script...cant seem to make it bloody work!!
> >
> > strText = "MY TEXT HERE
> > Do While InStr(strText, " ") > 0
> > strText = Replace(strText, " ", " ")
> > Loop
> > strText = Replace(strText, vbCrLf, "# ")
> > strTextWrap = WordWrap(strText, 80)
> >
> > out = out & AddBrToCrLf(strTextWrap)
> >
> >
> >
> > Function WordWrap(strTextToBeWrapped, intMaxLineLength)
> > Dim strWrappedText ' Result storage
> > Dim intLengthOfInput ' Length of original
> > Dim intCurrentPosition ' Where we're at now
> > Dim intCurrentLineStart ' Where the current line starts
> > Dim intPositionOfLastSpace ' Last space we saw
> > Dim strTempText
> >
> > intLengthOfInput = Len(strTextToBeWrapped)
> >
> > ' Start both of these at the beginning
> > intCurrentPosition = 1
> > intCurrentLineStart = 1
> >
> > ' Loop through until we get to the end
> > Do While intCurrentPosition < intLengthOfInput
> > ' If the current position is a space, make a note of
> > ' it's location for later use.
> >
> > If Mid(strTextToBeWrapped, intCurrentPosition, 1) = " " Then
> > intPositionOfLastSpace = intCurrentPosition
> > End If
> >
> > ' If we're at what should be the end of a line, we go back
> > ' to the last space we saw and cut the line there.
> > If intCurrentPosition = intCurrentLineStart + intMaxLineLength Then
> > ' Some debugging lines if something's not lining up.
> > ' Response.Write intCurrentLineStart & "<br/>"
> > ' Response.Write intPositionOfLastSpace & "<br/>"
> > ' Response.Write Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
> > intPositionOfLastSpace - intCurrentLineStart + 1)) & "<br/>"
> >
> > ' Append this latest line to our result
> >
> > ' response.Write Right(strWrappedText,4) & "<BR>"
> > ' response.Write "linebreak at= " & intCurrentLineStart & "<BR>"
> >
> > strTempText = Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
> > intPositionOfLastSpace - intCurrentLineStart + 1))
> > strWrappedText = strWrappedText & strTempText & "^" & vbCrLf
> >
> >
> > ' Reset the next line's starting point to the point we
> > ' used for the last one's end + 1.
> > intCurrentLineStart = intPositionOfLastSpace + 1
> >
> > ' Remove any leading spaces that might mess up our
> > ' character count. If you want to just pull of one,
> > ' switch this to a simple If conditional instead of
> > ' looping.
> > Do While Mid(strTextToBeWrapped, intCurrentLineStart, 1) = " "
> > intCurrentLineStart = intCurrentLineStart + 1
> > Loop
> > End If
> >
> > intCurrentPosition = intCurrentPosition + 1
> > Loop
> >
> >
> >
> >
> > ' Since the loop ends before we add the remaining text,
> > ' add remaining text as the last line.
> > strWrappedText = strWrappedText & Trim(Mid(strTextToBeWrapped,
> > intcurrentLineStart)) & vbCrLf
> >
> > WordWrap = strWrappedText
> > End Function
> >
> >
> > Function AddBrToCrLf(strInput)
> > strInput = Replace(strInput, vbCrLf, "<br>" & vbCrLf)
> > AddBrToCrLf = Replace(strInput, "#", "<br>" & vbCrLf)
> > End Function
> >
> >
> >
> >
> > "McKirahan" <News@McKirahan.com> wrote in message> > > "raj" <karwalr@hotmail.com> wrote in message
> > > news:477bcb83.0312150417.470a31c7@posting.google.c om...
> > > > Hi, ive got this script for aspin.com that wraps text to a specified
> > > > no of characters. Only problem is, it doesnt account for line breaks
> > > > (so any shorter lines dont get a vbCrLf and the alignment is messedhttp://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=4&txtCodeId>> > > > further down the line) Can anyone help with this. Cheers
> > > >
> > > > Function WordWrap(strTextToBeWrapped, intMaxLineLength)
> > > > Dim strWrappedText ' Result storage
> > > > Dim intLengthOfInput ' Length of original
> > > > Dim intCurrentPosition ' Where we're at now
> > > > Dim intCurrentLineStart ' Where the current line starts
> > > > Dim intPositionOfLastSpace ' Last space we saw
> > > > Dim strTempText
> > > >
> > > > intLengthOfInput = Len(strTextToBeWrapped)
> > > >
> > > > ' Start both of these at the beginning
> > > > intCurrentPosition = 1
> > > > intCurrentLineStart = 1
> > > >
> > > > ' Loop through until we get to the end
> > > > Do While intCurrentPosition < intLengthOfInput
> > > > ' If the current position is a space, make a note of
> > > > ' it's location for later use.
> > > >
> > > > If Mid(strTextToBeWrapped, intCurrentPosition, 1) = " " Then
> > > > intPositionOfLastSpace = intCurrentPosition
> > > > End If
> > > >
> > > > ' If we're at what should be the end of a line, we go back
> > > > ' to the last space we saw and cut the line there.
> > > > If intCurrentPosition = intCurrentLineStart + intMaxLineLength Then
> > > > ' Some debugging lines if something's not lining up.
> > > > ' Response.Write intCurrentLineStart & "<br/>"
> > > > ' Response.Write intPositionOfLastSpace & "<br/>"
> > > > ' Response.Write Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
> > > > intPositionOfLastSpace - intCurrentLineStart + 1)) & "<br/>"
> > > >
> > > > ' Append this latest line to our result
> > > >
> > > > response.Write "linebreak at= " & intCurrentLineStart & "<BR>"
> > > >
> > > > strTempText = Trim(Mid(strTextToBeWrapped, intcurrentLineStart,
> > > > intPositionOfLastSpace - intCurrentLineStart + 1))
> > > > strWrappedText = strWrappedText & strTempText & "^" & vbCrLf
> > > >
> > > > ' Reset the next line's starting point to the point we
> > > > ' used for the last one's end + 1.
> > > > intCurrentLineStart = intPositionOfLastSpace + 1
> > > >
> > > > ' Remove any leading spaces that might mess up our
> > > > ' character count. If you want to just pull of one,
> > > > ' switch this to a simple If conditional instead of
> > > > ' looping.
> > > > Do While Mid(strTextToBeWrapped, intCurrentLineStart, 1) = " "
> > > > intCurrentLineStart = intCurrentLineStart + 1
> > > > Loop
> > > > End If
> > > >
> > > > intCurrentPosition = intCurrentPosition + 1
> > > > Loop
> > > >
> > > > ' Since the loop ends before we add the remaining text,
> > > > ' add remaining text as the last line.
> > > > strWrappedText = strWrappedText & Trim(Mid(strTextToBeWrapped,
> > > > intcurrentLineStart)) & vbCrLf
> > > >
> > > > WordWrap = strWrappedText
> > > > End Function
> > >
> > >
> > > Which of these do you want?
> > >
> > > 1) "strTextToBeWrapped" will contain vbCrLf's that you want ignored;
> > >
> > > If so then try:
> > >
> > > strTextToBeWrapped = Replace(strTextToBeWrapped,vbCrLf," ")
> > >
> > >
> > > 2) "WordWrap()" should only process portions of "strTextToBeWrapped"
> > > between vbCrLf's;
> > >
> > > If so then try:
> > >
> > > strTextToBeWrapped = Replace(strTextToBeWrapped,vbCrLf,"<br>")
> > > strTextToBeWrappedNow = Split(strTextToBeWrapped,"<br>")
> > > For i = 0 To UBound(strTextToBeWrappedNow)
> > > If strTextToBeWrappedNow(i) <> "" Then
> > > Call WordWrap(strTextToBeWrappedNow(i), intMaxLineLength)
> > > End If
> > > Next
>
> Where on "aspin.com" did you find this WordWrap function?
>
> All I could fund was:
> This is a function to provide word wrap capability in your ASP pages.
>string> =6220
>
> I suspect that you're trying to pass in (to the function) the entire> rather than a single line.
>
> I wanted to read the function's documentation to better understand it --
> though I'll probably rewrite it anyway.
>
>
> Also, could your provide a statement of exactly what you're trying to do.
> For example,
>
> "I have a text file that I want reformatted so no single line exceeds 80
> bytes."
Are you working with a file containing HTML or plain text?
For example, if it's plain text like the Preamble to the Constitution of the
United States of America that follows (one sentence, no word-wrap):
We the people of the United States, in order to form a more perfect union,
establish justice, insure domestic tranquility, provide for the common
defense, promote the general welfare, and secure the blessings of liberty to
ourselves and our posterity, do ordain and establish this Constitution for
the United States of America.
Is the following the output you would like?
We the people of the United States, in
order to form a more perfect union,
establish justice, insure domestic
tranquility, provide for the common
defense, promote the general welfare,
and secure the blessings of liberty to
ourselves and our posterity, do ordain
and establish this Constitution for
the United States of America.
The above is the result of wrapping the Preamble at 40 bytes.
That is, no line contains more than 40 bytes.
The space causig the line break starts the next line.
Neither multiple spaces nor extra line ffeds are not removed.
Also, how will you bet the input text (by reading a file or via user input;
e.g. textarea)
and what will you do with the result (write a file or display in a Web
page)?
McKirahan Guest
-
Chris Hohmann #6
Re: text wrap problems...
"raj" <karwalr@hotmail.com> wrote in message
news:477bcb83.0312150417.470a31c7@posting.google.c om...Here's the response I posted in a similar thread.> Hi, ive got this script for aspin.com that wraps text to a specified
> no of characters. Only problem is, it doesnt account for line breaks
> (so any shorter lines dont get a vbCrLf and the alignment is messed up
> further down the line) Can anyone help with this. Cheers
[url]http://groups.google.com/groups?selm=eNyFXD3nDHA.2512%40TK2MSFTNGP09.phx.gb l[/url]
Chris Hohmann Guest



Reply With Quote

