Solved

Count Lines In textbox

Posted on 2004-04-04
2
253 Views
Last Modified: 2008-03-17
How do i count how many lines someone has typed into a text box?

Thanx in Advance
0
Comment
Question by:burnttime
  • 2
2 Comments
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 50 total points
ID: 10753606
you could try using split:

Private Sub Command1_Click()
Dim NumLines As Integer
Dim arrLines() As String
arrLines = Split(Text1.Text, vbCrLf)
NumLines = UBound(arrLines) + 1
MsgBox NumLines
End Sub
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10753648
If you need to disregard blank lines then use:

Private Function CountLines(txtBox As TextBox) As Long
Dim NumLines As Integer, i As Integer
Dim arrLines() As String
arrLines = Split(txtBox, vbCrLf)
NumLines = 0
For i = 0 To UBound(arrLines)
    If Trim$(arrLines(i)) <> "" Then
        NumLines = NumLines + 1
    End If
Next i
CountLines = NumLines
End Function


Private Sub Command1_Click()
MsgBox CountLines(Text1)
End Sub
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

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

12 Experts available now in Live!

Get 1:1 Help Now