Function GetAllLines(tb As TextBox) As String()
Dim res() As String, i As Long
' Activate soft line breaks. A soft line break
' corresponds to the CR-CR-LF sequence.
SendMessageByVal tb.hWnd, EM_FMTLINES, True, 0
' Retrieve all the lines in one operation.
' This operation leaves a trailing CR
' character for soft line breaks.
res() = Split(tb.Text, vbCrLf)
' We need a loop to trim the trailing CR
' character.
For i = 0 To UBound(res)
If Right$(result(i), 1) = vbCr Then
res (i) = Left$(res(i), Len(res(i)) - 1)
End If
Next
' Deactivate soft line breaks.
SendMessageByVal tb.hWnd, EM_FMTLINES, _
False, 0
GetAllLines = res()
End Function
|