I had being enjoying the use of a seemingly fantastic BASIC function by Andrew Brown. I am using it to count the words in each page. Unfortunate it is not accurate or consistent enough between pages for my needs. I tested OO's built in word count and was delighted to see that the selection count was very consistent. I basically want to tap into it and give it either a range or a string and have it return the word count as an integer. is this possible?
Bellow is the function by Andrew Brown. it does work, but just not for my needs.
Code: Select all
Function hotcount(aString)
'*******************************************
'Function: Count Words in provided string
'Author: Andrew Brown
'Last updated 18 March 2016
'Last updated by:Daniel Wilson
'*******************************************
' the ultimate, using the same breakiterator as the program
'
Dim mystartpos As Long
Dim numwords,nw
Dim nextwd As New com.sun.star.i18n.Boundary
Dim aLocale As New com.sun.star.lang.Locale
Dim brk
aLocale.Language="en"
' Urska, you may need to change the line above.
numwords=1 ' don't ask me why we need this
mystartpos=0
brk=CreateUNOService("com.sun.star.i18n.BreakIterator")
nextwd=brk.nextWord(aString,startpos,aLocale,com.sun.star.i18n.WordType.WORD_COUNT)
Do While nextwd.startPos<> nextwd.endPos
numwords=numwords+1
nw=nextwd.startpos
nextwd=brk.nextWord(aString,nw,aLocale,com.sun.star.i18n.WordType.WORD_COUNT)
Loop
hotcount=numwords
End Function