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
Printable View
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
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
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
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:
I'm fairly sure that will do it.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
Hope it helps :)
Thanks, HarryW. That really helped me.
Thank both of you very much
aki