'add a textbox with "multiline=true","scrollbars=2".
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 Declare Function SendMessageByNum Lib "USER32" _
Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessageByString Lib "USER32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam _
As Long, ByVal lParam As String) As Long
Function GetLineText(ByVal txtbox As TextBox, ByVal LineIndex As Long) As String '返回指定行的内容
Dim lc As Long, linechar As Long
linechar = SendMessageByNum(txtbox.hWnd, EM_LINEINDEX, LineIndex, 0)
lc = SendMessageByNum(txtbox.hWnd, EM_LINELENGTH, linechar, 0) + 1
GetLineText = String(lc + 2, 0)
Mid(GetLineText, 1, 1) = Chr(lc And &HFF)
Mid(GetLineText, 2, 1) = Chr(lc \ &H100)
lc = SendMessageByString(txtbox.hWnd, EM_GETLINE, LineIndex, GetLineText)
GetLineText = Left(GetLineText, lc)
End Function
Function lastline(ByVal txtbox As TextBox) As String
Dim linecount As Long
linecount = SendMessage(txtbox.hWnd, EM_GETLINECOUNT, 0, 0) - 1 '返回行数
lastline = GetLineText(txtbox, linecount)
End Function
Private Sub Command1_Click()
MsgBox lastline(Text1)
End Sub