To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Dec 25th, 2006, 10:07 AM   #1
om-yousif
Addicted Member
 
Join Date: Jul 06
Posts: 131
om-yousif is an unknown quantity at this point (<10)
Resolved [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
om-yousif is offline   Reply With Quote
Old Dec 25th, 2006, 10:26 AM   #2
MartinLiss
Administrator
 
MartinLiss's Avatar
 
Join Date: Sep 99
Location: Looking over your shoulder from San Jose, CA
Posts: 29,638
MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)
Re: count the number of words

VB Code:
  1. Dim strWords() As String
  2. Dim intCount As Integer
  3. Dim lngIndex As Long
  4. strWords = Split(MyData, " ")
  5. For lngIndex = 0 To UBound(strWords)
  6.     If Left$(LCase(strWords(lngIndex)), Len("university")) = "university" Then
  7.         intCount = intCount + 1
  8.     End If
  9. Next
  10. 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.
__________________
Tips, Examples & Tutorials:
A valuable forum toolGenerate unique TreeView keysTreeView with "open" and "closed folder" iconsTime code using GetTickCountHow to trap the Tab keyScroll a formNumberBox ActiveX controlColor a ListView rowAn InputBox formHow to use SaveSetting and GetSettingA program registration schemeSpellcheck a TextboxResize controlsOpen Windows Explorer at Last Visited PathA Blackjack GameCount lines of codePrivate Message ViewerCopy/Paste VB CodePaste VB Code Add-InInsert Procedure Names Add-InA calculator for the game of SpiderMy review of REALbasic 2008VB6 Debug TutorialPicture ViewerVBF Photo Contest Winners

Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
Marty
If someone helped you today then please consider rating their post.
MartinLiss is offline   Reply With Quote
Old Dec 25th, 2006, 10:57 AM   #3
om-yousif
Addicted Member
 
Join Date: Jul 06
Posts: 131
om-yousif is an unknown quantity at this point (<10)
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 ?
om-yousif is offline   Reply With Quote
Old Dec 25th, 2006, 11:32 AM   #4
sessi4ml
Fanatic Member
 
sessi4ml's Avatar
 
Join Date: Nov 06
Location: Near San Francisco
Posts: 833
sessi4ml will become famous soon enough (50+)
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 ]
sessi4ml is offline   Reply With Quote
Old Dec 25th, 2006, 12:13 PM   #5
MartinLiss
Administrator
 
MartinLiss's Avatar
 
Join Date: Sep 99
Location: Looking over your shoulder from San Jose, CA
Posts: 29,638
MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)MartinLiss is a name known to all (1000+)
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:
  1. Dim strWords() As String
  2. Dim intCount As Integer
  3. Dim lngIndex As Long
  4. Dim strSelected As String
  5. strSelected = LCase(Trim$(RichTextBox1.SelText))
  6. strWords = Split(RichTextBox1.Text, " ")
  7. For lngIndex = 0 To UBound(strWords)
  8.     If Left$(LCase(strWords(lngIndex)), Len(strSelected)) = strSelected Then
  9.         intCount = intCount + 1
  10.     End If
  11. Next
  12. MsgBox intCount - 1
__________________
Tips, Examples & Tutorials:
A valuable forum toolGenerate unique TreeView keysTreeView with "open" and "closed folder" iconsTime code using GetTickCountHow to trap the Tab keyScroll a formNumberBox ActiveX controlColor a ListView rowAn InputBox formHow to use SaveSetting and GetSettingA program registration schemeSpellcheck a TextboxResize controlsOpen Windows Explorer at Last Visited PathA Blackjack GameCount lines of codePrivate Message ViewerCopy/Paste VB CodePaste VB Code Add-InInsert Procedure Names Add-InA calculator for the game of SpiderMy review of REALbasic 2008VB6 Debug TutorialPicture ViewerVBF Photo Contest Winners

Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer.
Marty
If someone helped you today then please consider rating their post.
MartinLiss is offline   Reply With Quote
Old Dec 25th, 2006, 01:13 PM   #6
om-yousif
Addicted Member
 
Join Date: Jul 06
Posts: 131
om-yousif is an unknown quantity at this point (<10)
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
om-yousif is offline   Reply With Quote
Old Dec 25th, 2006, 01:26 PM   #7
sessi4ml
Fanatic Member
 
sessi4ml's Avatar
 
Join Date: Nov 06
Location: Near San Francisco
Posts: 833
sessi4ml will become famous soon enough (50+)
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 ]
sessi4ml is offline   Reply With Quote
Old Dec 26th, 2006, 01:16 PM   #8
om-yousif
Addicted Member
 
Join Date: Jul 06
Posts: 131
om-yousif is an unknown quantity at this point (<10)
Re: count the number of words

thanks ZenDisaster
this is good but i need to get the count# without changing colors
om-yousif is offline   Reply With Quote
Old Dec 26th, 2006, 01:33 PM   #9
om-yousif
Addicted Member
 
Join Date: Jul 06
Posts: 131
om-yousif is an unknown quantity at this point (<10)
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.
om-yousif is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:32 PM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.