Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to count the line in the textbox?

Posted on 2011-09-27
4
Medium Priority
?
502 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 2000 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 49

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

772 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