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

x
?
Solved

Count Lines In textbox

Posted on 2004-04-04
2
Medium Priority
?
272 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 200 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

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…
Suggested Courses

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