How to count the line in the textbox?

I want to count the lline in the textbox and put it to the msgbox.  I have a textbox name Text1.Text. It has multiple lines. I want to count the line.. How pls?
Text1.Text

Private Sub Command1_Click()
'text1.txt
msgbox no. of lines
End Sub
Whing Dela CruzAsked:
Who is Participating?
 
GrahamSkanConnect With a Mentor RetiredCommented:
That does not apply if there are multiple lines because one or more are too long and restart on another line
0
 
GrahamSkanRetiredCommented:
If the lines are separated with the standard vbCrLf, simply do

linecount = Ubound(Split(Text1.Text, vbCrlf)) + 1
0
 
Whing Dela CruzAuthor Commented:
Thanks a lot...
0
 
Martin LissOlder than dirtCommented:
I don't actually see an answer here for when you can't use vbCrLf so here goes.


Option Explicit
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 Long
    
    '-- Get the line count of Textbox
    LIneCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)

Open in new window


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.