Count number of lines/returns in a textbox

By | 2002-06-01

Simply counts the number of lines in a textbox (the textbox should be multiline=true, otherwise it is pretty useless). Put this in a module so it can be reused.

Original Author: Jono Spiro

Inputs

USAGE–countLines(the textbox)
EXAMPLE–countLines(text1)

Returns

Returns the number of lines in a textbox.

Code

Public Function countLines(textBox As textBox) As Long
Dim A%, B$
A% = 1
B$ = textBox.text
Do While InStr(B$, Chr$(13))
  A% = A% + 1
  B$ = Mid$(B$, InStr(B$, Chr$(13)) + 1)
Loop
countLines = CStr(A%)
End Function

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.