Solved

Count Lines In textbox

Posted on 2004-04-04
2
258 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…

816 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

11 Experts available now in Live!

Get 1:1 Help Now