Solved

How to count the line in the textbox?

Posted on 2011-09-27
4
438 Views
Last Modified: 2012-06-21
I want to count the lline in the textbox and put it to the msgbox.  I have a textbox name Text1.Text. It has multiple lines. I want to count the line.. How pls?
Text1.Text

Private Sub Command1_Click()
'text1.txt
msgbox no. of lines
End Sub
0
Comment
Question by:Whing Dela Cruz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36712381
If the lines are separated with the standard vbCrLf, simply do

linecount = Ubound(Split(Text1.Text, vbCrlf)) + 1
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 36712407
That does not apply if there are multiple lines because one or more are too long and restart on another line
0
 

Author Closing Comment

by:Whing Dela Cruz
ID: 36712571
Thanks a lot...
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 36712891
I don't actually see an answer here for when you can't use vbCrLf so here goes.


Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const EM_GETLINECOUNT = &HBA



    Dim LineCount As Long
    
    '-- Get the line count of Textbox
    LIneCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)

Open in new window


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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month7 days, 13 hours left to enroll

632 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