 |
 |

06-20-2003, 02:45 AM
|
|
Junior Contributor
|
|
Join Date: May 2003
Posts: 269
|
|
Word Count
|
Hi,
I have a text box and i managed to do a character count, but im having probs with a word count - has anyone got some ideas? i only want a realy basic one.
also i have a find command - it works but only for the first instance - how can i make it find the next and the next and so on?
thanks, simon. 
|
|

06-20-2003, 03:15 AM
|
 |
Junior Contributor
|
|
Join Date: Feb 2003
Location: Philippines
Posts: 336
|
|
One way to do this is using Split() function
Code:
Dim aWords() as string
Dim inumwords as integer
aWords = Split(text1.text, " ") 'splits your strings separated by space
inumwords = Ubound(sWords) +1 'counts the elements of your array
lblnumwords = inumwords 'display it on a label
I'm not sure if this is the best solution 
|
__________________
"Everything should be made as simple as possible, but not simpler."
- Albert Einstein
|

06-20-2003, 04:41 AM
|
|
Junior Contributor
|
|
Join Date: May 2003
Posts: 269
|
|
|
thanks i tried that but it wouldnt seem to work. any ideas why? i get the idea but i think the ubound is making it stop.
|
|

06-20-2003, 04:45 AM
|
|
Newcomer
|
|
Join Date: Jun 2003
Posts: 12
|
|
Quote: Originally Posted by starbitz One way to do this is using Split() function
Code:
Dim aWords() as string
Dim inumwords as integer
aWords = Split(text1.text, " ") 'splits your strings separated by space
inumwords = Ubound(sWords) +1 'counts the elements of your array
lblnumwords = inumwords 'display it on a label
I'm not sure if this is the best solution 
Code:
Dim aWords() As String
aWords = Split(Text1.Text, " ")
lblNumWords = Int(UBound(aWords) + 1)
You used aWords at the first point and sWords at the next so I fixed that. You can also make it shorter, no need to store it in inumwords. 
|
|

06-20-2003, 04:46 AM
|
|
Newcomer
|
|
Join Date: Jun 2003
Posts: 12
|
|
Quote: Originally Posted by S1mon thanks i tried that but it wouldnt seem to work. any ideas why? i get the idea but i think the ubound is making it stop.
It didnt work because he used two different names for the same thing
|
|

06-20-2003, 04:50 AM
|
|
Junior Contributor
|
|
Join Date: May 2003
Posts: 269
|
|
thanks dude - works!! 
|
|

06-20-2003, 05:08 AM
|
 |
Junior Contributor
|
|
Join Date: Feb 2003
Location: Philippines
Posts: 336
|
|
Quote: Originally Posted by TLS
Quote: Originally Posted by S1mon thanks i tried that but it wouldnt seem to work. any ideas why? i get the idea but i think the ubound is making it stop.
It didnt work because he used two different names for the same thing
Sorry about that  What really happens was a typo error, coz initially, I used the sWords variable. I changed it to aWords becuase I realized it was an array (coding practice). I forgot to change the third 
|
__________________
"Everything should be made as simple as possible, but not simpler."
- Albert Einstein
|

06-20-2003, 09:28 AM
|
 |
Retread
Retired Moderator * Expert *
|
|
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
|
|
|
That is why Option Explicit needs to be at the top of the code window. Always. It catches stuff like that at runtime.
~MikeJ
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|