Solved

How to count the line in the textbox?

Posted on 2011-09-27
4
344 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
  • 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 45

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now