Number of lines in a multiline textbox

How can I get the number of lines typed in a multiline textbox control?
nashualdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
0
 
vb_elmarCommented:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
 
Const EM_GETLINECOUNT = &HBA

 
Private Sub Command1_Click()

  MsgBox SendMessage(RichTextBox1.hWnd, EM_GETLINECOUNT, 0, 0)

End Sub
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
BrianGEFF719Commented:
Or if you want a very un-orthodox method:

dim strString as string
dim numLines as integer
dim myArray() as string
strString = text1.text
myArray() = Split(strString,vbcrlf)
numLines = myArray.UBound


msgbox "The text box has : " & numLines & " Lines"


I do not recommend using this method in any commerical application.

Brian
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Brian: the split method only returns the number of hard breaks (via the crlf characters), but not those lines that are wrapped by the length of the line...
0
 
BrianGEFF719Commented:
angelIII: You are very right.

I was just providing it as an example. Nothing more. I would never recommmend anything like that in a serious application.


Brian
0
 
nashualdAuthor Commented:
Thank's everybody!
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.