[RESOLVED] count the number of words
i have a richtextbox
if i clicked any word i need to get the number of the same words in the text
which are befor the word clicked
example text:
University of Liverpool
Founded in 1881, the University of Liverpool has earned an international reputation for high quality and is one of the most highly respected educational institutions in the UK. It has been associated with no fewer than eight Nobel Laureates.
Laureate Online Education, formerly known as KIT eLearning, has acted as the e-learning partner of the University of Liverpool since 1999. It specialises in delivering 100% online academic education on a global basis - tailored for the needs of working professionals worldwide.
Laureate Online Education has developed Europe's truly international online Master programmes, using specially adapted versions of University of Liverpool campus-taught degrees.
if i clicked the word University that is underlined
i should get the value =3
by ignoring the last word because it cames after the one choosen
how can i do this
Re: count the number of words
VB Code:
Dim strWords() As String
Dim intCount As Integer
Dim lngIndex As Long
strWords = Split(MyData, " ")
For lngIndex = 0 To UBound(strWords)
If Left$(LCase(strWords(lngIndex)), Len("university")) = "university" Then
intCount = intCount + 1
End If
Next
MsgBox intCount - 1
The Left$ portion of the If statement takes care of the situation where the word you want to count is followed by a period, comma, etc.
Re: count the number of words
i need the code to be general for any word
University is just an example
and what is MyData ?
Re: count the number of words
Why not count the spaces.
Code:
For a=1 to len(LineOfText)
if Mid(LineOfText(a,1)=" " then Count=count+1
next a
' and for the last word of the sentence
count=count+1
This is very simple way of counting
Re: count the number of words
Quote:
Originally Posted by om-yousif
i need the code to be general for any word
University is just an example
and what is MyData ?
MyData was just a placeholder for my testing, and I assumed you knew how to tell which word was selected. Here is a better example.
VB Code:
Dim strWords() As String
Dim intCount As Integer
Dim lngIndex As Long
Dim strSelected As String
strSelected = LCase(Trim$(RichTextBox1.SelText))
strWords = Split(RichTextBox1.Text, " ")
For lngIndex = 0 To UBound(strWords)
If Left$(LCase(strWords(lngIndex)), Len(strSelected)) = strSelected Then
intCount = intCount + 1
End If
Next
MsgBox intCount - 1
Re: count the number of words
MartinLiss
this code will count all words in the text and i need it to stop counting when it reaches the word selected
i.e # words befor selected
Re: count the number of words
Yes, I saw that after I posted. I must remember to read the thread i.e. all the words not just the ones I like.
Re: count the number of words
thanks ZenDisaster
this is good but i need to get the count# without changing colors
Re: count the number of words
Yes :) thats it
can it ignor any word between brackets
i mean if the same word was between ( ) it wil not be counted
there may be more than one word between ( )
example:
University of Liverpool
Founded in 1881, the (University of Liverpool has earned )an international reputation for high quality and is one of the most highly respected educational institutions in the UK. It has been associated with no fewer than eight Nobel Laureates.
Laureate Online Education, formerly known as KIT eLearning, has acted as the e-learning partner of the University of Liverpool since 1999. It specialises in delivering 100% online academic education on a global basis - tailored for the needs of working professionals worldwide.
if i choose the underlined word it should return 2 so it will ignor the word which is between ( )