Results 1 to 3 of 3

Thread: [RESOLVED]Line Breaking...

Threaded View

  1. #1

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Resolved [RESOLVED]Line Breaking...

    I've recently wrote a routine to replace visual line breaks by real ones in a RichTextBox. It works like intended, but is extremely slow. Would someone know how could it be accelerated?

    Here's the code:

    VB Code:
    1. Public Sub InsertLineBreaks(rtb As RichTextBox)
    2.  
    3. Dim xPos() As Long
    4. Dim lastLine As Long, curLine As Long
    5. Dim i As Long, l As Long
    6.  
    7. Do
    8.    rtb.Text = Replace$(rtb.Text, vbCrLf & vbCrLf, vbCrLf)
    9. Loop While InStr(1, rtb.Text, vbCrLf & vbCrLf)
    10.  
    11. ReDim xPos(rtb.GetLineFromChar(Len(rtb.Text)) - 1)
    12.  
    13. For i = 0 To Len(rtb.Text)
    14.     curLine = rtb.GetLineFromChar(i)
    15.     If curLine <> lastLine Then
    16.         xPos(UBound(xPos)) = i + 1
    17.         l = l + 1
    18.     End If
    19.     lastLine = rtb.GetLineFromChar(i)
    20. Next
    21.  
    22. rtb.Text = Replace$(rtb.Text, vbCrLf, " ")
    23.  
    24. If UBound(xPos) > 0 Then
    25.     For i = 0 To UBound(xPos)
    26.         rtb.SelStart = xPos(i) - (i * 2) + ((i - 1) * 2)
    27.         rtb.SelLength = 1
    28.         If rtb.SelText <> " " Then rtb.SelStart = rtb.SelStart - 1: rtb.SelLength = 1
    29.         rtb.SelText = Chr(201)
    30.     Next
    31.     rtb.Text = Replace$(rtb.Text, Chr(201), vbCrLf)
    32. End If
    33.  
    34. End Sub
    Last edited by Max_aka_NOBODY; Apr 21st, 2005 at 07:49 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width