Solved

Count Lines In textbox

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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.
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…

726 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