?
Solved

Number of lines in a multiline textbox

Posted on 2006-04-25
6
Medium Priority
?
975 Views
Last Modified: 2013-12-25
How can I get the number of lines typed in a multiline textbox control?
0
Comment
Question by:nashuald
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16538506
0
 
LVL 17

Accepted Solution

by:
vb_elmar earned 200 total points
ID: 16540653
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
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 16540912
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16541142
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
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 16541219
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
 

Author Comment

by:nashuald
ID: 16547174
Thank's everybody!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question