How do I get the number of lines of text in a text box (textbox)

Source: Internet
Author: User
Text Box calculates the number of lines of text entered in a text box can be returned using SendMessage, and when a line of text is wrapped, it is treated as a new line, and the number of newline characters in the text is not simple.

Add the following API function declarations to the general declarations area of the module file.

Option Explicit

Public Declare Function Sendmessagelong Lib _

"User32" Alias "SendMessageA" _

(ByVal hwnd as Long, _

ByVal wmsg as Long, _

ByVal WParam as Long, _

ByVal LParam as Long) as long

Public Const Em_getlinecount = &hba

Form Code

Sub Text1_change ()

Dim LineCount as Long

On local Error Resume Next

' Get/show number of lines of text

LineCount = Sendmessagelong (Text1.hwnd, Em_getlinecount, 0&, 0&)

Label1.Caption = Format (LineCount, "##,###")

End Sub

Note: To make this program successful, set the Multiline property of the text box to true at design time.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.