Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Word Count


Reply
 
Thread Tools Display Modes
  #1  
Old 06-20-2003, 02:45 AM
S1mon S1mon is offline
Junior Contributor
 
Join Date: May 2003
Posts: 269
Default 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.
Reply With Quote
  #2  
Old 06-20-2003, 03:15 AM
starbitz's Avatar
starbitz starbitz is offline
Junior Contributor
 
Join Date: Feb 2003
Location: Philippines
Posts: 336
Default

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
Reply With Quote
  #3  
Old 06-20-2003, 04:41 AM
S1mon S1mon is offline
Junior Contributor
 
Join Date: May 2003
Posts: 269
Default

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.
Reply With Quote
  #4  
Old 06-20-2003, 04:45 AM
TLS TLS is offline
Newcomer
 
Join Date: Jun 2003
Posts: 12
Default

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.
Reply With Quote
  #5  
Old 06-20-2003, 04:46 AM
TLS TLS is offline
Newcomer
 
Join Date: Jun 2003
Posts: 12
Default

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
Reply With Quote
  #6  
Old 06-20-2003, 04:50 AM
S1mon S1mon is offline
Junior Contributor
 
Join Date: May 2003
Posts: 269
Default

thanks dude - works!!
Reply With Quote
  #7  
Old 06-20-2003, 05:08 AM
starbitz's Avatar
starbitz starbitz is offline
Junior Contributor
 
Join Date: Feb 2003
Location: Philippines
Posts: 336
Default

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
Reply With Quote
  #8  
Old 06-20-2003, 09:28 AM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
Default

That is why Option Explicit needs to be at the top of the code window. Always. It catches stuff like that at runtime.

~MikeJ
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
count word occurances in text MajorNME General 14 01-26-2003 10:50 PM
Word Count KidCoder General 16 07-27-2002 08:50 PM
VB + WORD.. get page count.. mohanakannan Word, PowerPoint, Outlook, and Other Office Products 1 01-22-2002 10:45 AM
word count in summary of property page JDavis Word, PowerPoint, Outlook, and Other Office Products 2 10-22-2001 11:52 AM
Pausing VBA after a Shell Command matt_wendling Word, PowerPoint, Outlook, and Other Office Products 10 10-10-2001 09:07 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->