Hello,
Recently I have use the above code which was displayed by Koolsid I belive.
I have used it before with no single problem up to 1200 lines .
But that was then, now I have RTB up to 3000 lines.
Reads fine until hits 2020 line and from that moment returns to the 1st line
and continuously duplicate it to the end of calculated number of all lines.
In this code, is there a buffer limitation ?
Is there something I don’t know and should know?

Code:

Option Explicit 

Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
    
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_GETSEL = &HB0
Private Const EM_LINEINDEX = &HBB
Private Const EM_LINELENGTH = &HC1
Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_GETLINE = &HC4
  Dim RTBLineCount As Long, Charindex As Long
  Dim FirstChar As Long, RowLength As Long, CursorPos As Long, nLine As Long
  Dim Buffer() As Byte, LineText A

************************************

Sub part

RTBLineCount = SendMessage(RichTextBox1.hwnd, EM_GETLINECOUNT, 0, 0)

    
    
    For i = 0 To RTBLineCount - 1
        
        ccnt = ccnt + 1
        Charindex = SendMessage(RichTextBox1.hwnd, EM_LINEINDEX, ByVal i, ByVal CLng(0))
    
        RichTextBox1.SelStart = Charindex
    
        CursorPos = SendMessage(RichTextBox1.hwnd, EM_GETSEL, 0, ByVal 0&) \ 65536
        nLine = SendMessage(RichTextBox1.hwnd, EM_LINEFROMCHAR, CursorPos, ByVal 0&)
        FirstChar = SendMessage(RichTextBox1.hwnd, EM_LINEINDEX, nLine, ByVal 0&)
        RowLength = SendMessage(RichTextBox1.hwnd, EM_LINELENGTH, FirstChar, ByVal 0&)
        ReDim Buffer(RowLength + 1)
        Buffer(0) = RowLength + 1

        SendMessage RichTextBox1.hwnd, EM_GETLINE, nLine, Buffer(0)
        LineText = Left$(StrConv(Buffer, vbUnicode), RowLength-6) ' single line, less 6 right cut.
        
         
        ' ***************
       'LineText = Replace(LineText, "  ", " ") good but not to be use here
      
	TX = Trim(LineText)
             Do While InStr(TX, "  ")
        TX = Replace$(TX, "  ", " ") 
             Loop
              
       RichTextBox3.Text = RichTextBox3.Text & TX & vbNewLine
       
       Next i