Results 1 to 5 of 5

Thread: Character Count & Word Count

  1. #1

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Character Count & Word Count

    How Do I do this with a richtextbox and make it display either character or word count in another textbox

    Thanks for your help,

    lavarock09

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Character Count & Word Count

    To find the length of the text in a textbox you can use :

    VB Code:
    1. RichTextBox.Text = Len(Text1.Text)

    That should be in the _Change event of Text1.


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Character Count & Word Count

    For word count you can do something like this (if you assume that every word is separated by a space and not other characters) :

    VB Code:
    1. Private Sub Text1_Change()
    2.     Text2.Text = UBound(Split(Text1.Text, " "))
    3. End Sub


    Has someone helped you? Then you can Rate their helpful post.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Character Count & Word Count

    To take manavo11's suggestion just a little step further, try this:
    VB Code:
    1. Private Function GetWordCount(ByVal pstrText As String) As Long
    2.  
    3.     pstrText = Trim(Replace(pstrText, "-" & vbNewLine, ""))
    4.    
    5.     pstrText = Trim(Replace(pstrText, vbNewLine, " "))
    6.    
    7.     Do While pstrText Like "*  *"
    8.         pstrText = Replace(pstrText, "  ", " ")
    9.     Loop
    10.    
    11.     GetWordCount = 1 + UBound(Split(pstrText, " "))
    12. End Function
    13.  
    14. Private Sub Command1_Click()
    15. MsgBox GetWordCount(RichTextBox1.Text)
    16. End Sub

  5. #5

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Character Count & Word Count

    Excellent, Exactly what I wanted,

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width