|
-
Dec 25th, 2006, 10:07 AM
#1
Thread Starter
Addicted Member
[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
-
Dec 25th, 2006, 10:26 AM
#2
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.
-
Dec 25th, 2006, 10:57 AM
#3
Thread Starter
Addicted Member
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 ?
-
Dec 25th, 2006, 11:32 AM
#4
Fanatic Member
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
Alpha Micro: Alpha Basic, AS400 V5r2, EDI (Trusted Link/ Inovis.com),Access AS/400 via VB6, Qbasic for data conversions. A mix of Hardware too. ASCII Table , New Number to Words/66 digits , AS/400(v5r2) VB6 Viewer/Ask for code(ODBC) ^ What Is Transferring? , Check your Ports #Perfect Passwords , *Slide Bar Example , Logoff, Restart, Shut-Down PC *Keep Form On Top , Opaque Form ^ Create Objects at Run Time @ Check Key Caps Locks # GetTickCount(System Up Time) * Convert text to Excel & Collected Icons + Resize: Form/Text box ^ PC GateWay via Shell $ Drag & Drop Game ! PopUpMenu *Print File/no Open# Timer on Mult Forms ~ Splash & Mult Forms & Lots of Comments + Random/Timer/Guess * Dec >Hex >Oct >Bin % Get MAC (NIC) < saving to Registry > Wookiee Cookies \ BackUpDisk / World Conection SpeedTest $ Glossary Commonly Used Terms # phonetic list @ Detailed Computer Scan
When posting Code, Use tags.. [CODE] *Your Code* [/CODE]
-
Dec 25th, 2006, 12:13 PM
#5
Re: count the number of words
 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
-
Dec 25th, 2006, 01:13 PM
#6
Thread Starter
Addicted Member
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
-
Dec 25th, 2006, 01:26 PM
#7
Fanatic Member
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.
Alpha Micro: Alpha Basic, AS400 V5r2, EDI (Trusted Link/ Inovis.com),Access AS/400 via VB6, Qbasic for data conversions. A mix of Hardware too. ASCII Table , New Number to Words/66 digits , AS/400(v5r2) VB6 Viewer/Ask for code(ODBC) ^ What Is Transferring? , Check your Ports #Perfect Passwords , *Slide Bar Example , Logoff, Restart, Shut-Down PC *Keep Form On Top , Opaque Form ^ Create Objects at Run Time @ Check Key Caps Locks # GetTickCount(System Up Time) * Convert text to Excel & Collected Icons + Resize: Form/Text box ^ PC GateWay via Shell $ Drag & Drop Game ! PopUpMenu *Print File/no Open# Timer on Mult Forms ~ Splash & Mult Forms & Lots of Comments + Random/Timer/Guess * Dec >Hex >Oct >Bin % Get MAC (NIC) < saving to Registry > Wookiee Cookies \ BackUpDisk / World Conection SpeedTest $ Glossary Commonly Used Terms # phonetic list @ Detailed Computer Scan
When posting Code, Use tags.. [CODE] *Your Code* [/CODE]
-
Dec 26th, 2006, 01:16 PM
#8
Thread Starter
Addicted Member
Re: count the number of words
thanks ZenDisaster
this is good but i need to get the count# without changing colors
-
Dec 26th, 2006, 01:33 PM
#9
Thread Starter
Addicted Member
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 ( )
Last edited by om-yousif; Dec 26th, 2006 at 01:39 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|