Try including all permutations of ways to make a line feed:
Code:
Public Function GetLine(ByVal MultiLineText As String, _
Optional ByVal LineNo As Integer = 0 _
) As String
Dim arrSentences() As String ' Create a String Array
If Trim(MultiLineText) = vbNullString Then Exit Function
' Normalize any alternates
' First make sure there is only one type of character
MultiLineText = Replace(MultiLineText, VbCr, VbLf)
' Now you might have single instances of VbLf, or cases
' of VbLf & VbLf where you previously had VbCrLf.
' Eliminate duplicates.
MultiLineText = Replace(MultiLineText, VbLf & VbLf, VbLf)
' Now do the split
' Split the entire text into a array
' considering Line Feeds as the delimiter
arrSentences = Split(Trim(MultiLineText), vbLf)
' Now return the right element out of the array (zero-based)
GetLine = arrSentences(LineNo)
End Function
[u]
CALLING THE FUNCTION</u>
Code:
Private Sub Command1_Click()
MsgBox GetLine(Text1.Text, 3) ' To Retrieve the 3rd Line
MsgBox GetLine(Text1.Text, 7) ' To Retrieve the 7th Line
MsgBox GetLine(Text1.Text) ' To Retrieve the 1st (that is, the zeroeth) Line
End Sub