以下方法將文本框中內容讀入字符串數組中。行數即為Ubound(t)+1
Dim t() As String, i As Integer
t = Split(Text1.Text, vbCrLf)
For i = 0 To UBound(t)
Debug.Print t(i)
Next
如果只需要行數,不需要讀出,可用以下方法:
*API函數聲明
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const EM_GETLINECOUNT = &HBA
注釋:在程序中調用
LineCnt = SendMessage(ctl.hwnd, EM_GETLINECOUNT, 0, 0)
注釋:LineCnt即為此TextBox的行數。