Results 1 to 5 of 5

Thread: Word count

  1. #1
    Guest

    Question

    Does anyone know how to create word count in VB?
    I just want to count words in writing program, such as, MS Word or Wordpad.

    Please let me know if you know.

    Thank you
    Aki

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Post

    Something like this?
    Code:
    Function wordcount(txt as string) ' returns the amount of word in txt
        Dim pos As Long
        If Len(txt) = 0 Then Exit Function
        pos = InStr(txt, " ")
        Do Until pos = 0
            wordcount = wordcount + 1
            pos = InStr(pos + 1, txt, " ")
        Loop
                wordcount = wordcount + 1
    End Function
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Guest

    Thanks

    Thanks Kedaman.
    I am pretty sure that will help me.
    but one more question.
    Can I specify a vocabulary?
    I mean, for example, a user can put any vocabulary in the text box, and count. like, How many vacabulary "car" are there in a text?

    I will try my best, but if anyone konws the answer, PLEASE tell me.

    Thanks
    aki

  4. #4
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    You could use Kedaman's code almost the same as it is, but instead of searching for the string " " you're looking for your word. So it would look something like this:

    Code:
    Function wordcount(txt as string, word as string) ' returns the amount of word in txt
        Dim pos As Long
        If Len(txt) = 0 Then Exit Function
        pos = InStr(txt, word)
        Do Until pos = 0
            wordcount = wordcount + 1
            pos = InStr(pos + len(word), txt, word)
        Loop
                wordcount = wordcount + 1
    End Function
    I'm fairly sure that will do it.

    Hope it helps
    Harry.

    "From one thing, know ten thousand things."

  5. #5
    Guest

    Talking

    Thanks, HarryW. That really helped me.
    Thank both of you very much

    aki


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width