[HELP] Count Lines In Textbox

counting the lines in a textbox

Page 1 of 1

1 Replies - 4554 Views - Last Post: 09 September 2009 - 08:20 PM Rate Topic: -----

#1 TheSolid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-August 09

[HELP] Count Lines In Textbox

Posted 09 September 2009 - 05:50 PM

Ok, So I am making this awesome Notepad type thing, and I am making it have a statusbar that tells you How many Characters, Words, and Lines are in the textbox.

Here is the code for it...

	Public Shared Function CountWords(ByVal Text As String) As Integer
		Dim Regex As New System.Text.RegularExpressions.Regex("\w+")
		Return Regex.Matches(Text).Count
	End Function
	Private Sub doc_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles doc.TextChanged
		Lbl_Characters.Text = Len(doc.Text)
		Lbl_Words.Text = CountWords(doc.Text)
	End Sub

As you may see...I have Characters and Words, but for some reason I cannot get the lines to count >.<
If I could have any help that would be great. Thankz

Is This A Good Question/Topic? 0
  • +

Replies To: [HELP] Count Lines In Textbox

#2 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: [HELP] Count Lines In Textbox

Posted 09 September 2009 - 08:20 PM

If the text is wrapping then probably just one continuous line. If the textbox is set to start new line when users press Enter then perhaps can count a return character?

Check this link: http://www.vbforfree.com/?p=375

This post has been edited by June7: 09 September 2009 - 08:25 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1