• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 142
  • Last Modified:

How to count the number of words in RTF

How can I count the number of words in a RichText box using VB code?
0
mcdonald_g
Asked:
mcdonald_g
1 Solution
 
VbmasterCommented:
Use this function, you call it with code like

  Number_of_words_in_richtextbox = CountWords(The_name_of_the_richtextbox.Text)



Function CountWords(Text As String) As Long

  Dim NrTecken As Long
  Dim OldNrTecken As Long
  Dim Char As String
 
  CountChar = 0
  OldNrTecken = 1
  NrTecken = InStr(Text, " ")
  Do Until (NrTecken = 0)
    If (NrTecken > OldNrTecken + 1) Then
      CountWords = CountWords + 1
    End If
    OldNrTecken = NrTecken
    NrTecken = InStr(NrTecken + 1, Text, " ")
  Loop

End Function
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now