web development India freelance website designer
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

1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550

Freelance ASP PHP web development | Web developer India Web development India| Prayagasoft - web designer India, Ecommerce developer india, Ecommerce design