Is there any method from which I can get the line count in a
RichTextBox?
Printable View
Is there any method from which I can get the line count in a
RichTextBox?
I'm not sure if this is what you are after.
VB Code:
Option Explicit Private Sub Command1_Click() Dim LineCount On Error GoTo LineErr LineCount = Split(RichTextBox1.Text, vbCrLf) MsgBox "Line count = " & UBound(LineCount) + 1 Exit Sub LineErr: MsgBox "Line count = 0" End Sub
You can also use API like this:
VB Code:
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 Const EM_GETLINECOUNT = &HBA Dim linecount As Integer '//////////////////////////////////////////////////////// linecount = SendMessage(RichTextBox1.hwnd, EM_GETLINECOUNT, 0, 0) MsgBox linecount
Faster:
VB Code:
Private Const EM_GETLINECOUNT = &HBA 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 Sub Command1_Click() MsgBox SendMessage(Me.RichTextBox1.hwnd, EM_GETLINECOUNT, ByVal CLng(0), ByVal CLng(0)) End Sub
;)
Damn API again, I have to learn about them someday.
oh well,
win some lose some :rolleyes: :p