VB6Quickly Extract All Lines in a Multiline TextBox Control

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
Listing 1. The ability to activate soft line breaks and the new VB6 Split function make it easy to retrieve all the individual lines of a word processing-like TextBox and put them into an array of Strings.