text wrap problems...

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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>...
    3. 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....
    4. 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...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default 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
    > Next
    raj Guest

  5. #4

    Default Re: text wrap problems...

    "raj" <karwalr@hotmail.com> wrote in message
    news:477bcb83.0312160129.539a8b36@posting.google.c om...
    > 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
    > > 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

  6. #5

    Default Re: text wrap problems...

    "McKirahan" <News@McKirahan.com> wrote in message
    news:ZuGDb.407540$ao4.1336315@attbi_s51...
    > "raj" <karwalr@hotmail.com> wrote in message
    > news:477bcb83.0312160129.539a8b36@posting.google.c om...
    > > 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
    > > > 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."

    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

  7. #6

    Default 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
    Here's the response I posted in a similar thread.
    [url]http://groups.google.com/groups?selm=eNyFXD3nDHA.2512%40TK2MSFTNGP09.phx.gb l[/url]


    Chris Hohmann Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139