You might like this code block better. I think there's some issue with vbcr/vblinefeed/vbnewline so you might want to look into that.
Anyways... y is the position of the CR just before the last line, x is the position after the last CR, and of course LastLine is the last line of text.Code:Private Sub Text1_KeyPress(KeyAscii As Integer) Dim x As Long Dim y As Long Dim found As Boolean Dim LastLine As String If KeyAscii = vbKeyReturn Then x = Text1.SelStart y = x While y > 1 And found = False y = y - 1 If Mid$(Text1.Text, y, 1) = vbCr Then found = True End If Wend If y = 0 Then y = 1 LastLine = Mid$(Text1.Text, y, x - y + 1) Debug.Print LastLine End If End Sub
Hope this helps, I didn't get a chance to polish it up.
- Dim A




Reply With Quote