Often, you may need to know how many lines of text there are in a multi-line
textbox. While Visual Basic makes it easy to determine how many paragraphs the
textbox contains, using code like so:Private Sub Command1_Click()
Dim myParas As Variant
myParas = Split(Text1, vbNewLine)
MsgBox UBound(myParas) + 1
End Sub
This code, as you can see, only parses out hard carriage returns; whereas you
want to know how many lines of text the control contains.
To accomplish this task, you'll need to resort to the SendMessageAsLong() API
function. This function conforms to the following syntax:Private Declare Function SendMessageAsLong Lib "user32" _
Alias "SendMessageA" (ByVal hWnd As Long,
ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
To obtain the number of lines, you pass in the EM_GETLINECOUNT
constant in the
wMsg parameter. Declare this constant like this:Const EM_GETLINECOUNT = 186
Finally, to use the function, pass in the handle to the textbox from which you
want to retrieve the line count, as well as the wMsg we mentioned earlier.
Example code might look like so:
Private Sub Command2_Click()
Dim lCount As Long
lCount = SendMessageAsLong(Text1.hWnd, EM_GETLINECOUNT, 0, 0)
MsgBox lCount
End Sub
Counting lines in a multi-line textbox
By ElementK Journals, published on 18 Jul 2001
| Filed in
You might also like...
VB 6 forum discussion
-
CorelDRAW VBA: cdrTraceLineDrawing FAILS, producing single linear path instead of Centerline trace?
by dancemanj (0 replies)
-
client/server application using activex
by beautifulheart (0 replies)
-
System Error &H8007007E. The specifed module could not be found.
by swiftsafe (5 replies)
-
Invitation to take part in an academic research study
by researchlab (0 replies)
-
Send SMS with SMPP
by mmahmoud (0 replies)
VB 6 podcasts
-
Stack Overflow Podcast: Podcast #45 – Keeping it Sharp
Published 7 years ago, running time 0h54m
Our guest this week is Eric Lippert – language architect extraordinaire and famous for all his work at Microsoft in developing their languages Eric joined Microsoft right out of college and was originally working on VB It’s time for everyone’s favorite game: Name the Worst Feature of that Microso.
Comments