I am using ‘LibreOffice 3.4 Basic Programmer’s Guide · September 2011’ and Andrew Pitonyak’s ‘OpenOffice.org Macros Explained’ as my references.
With my cursor, I get the expected behaviour from cursor.gotonextparagraph and cursor.gotonext word, but cursor.gotonextsentence goes into a busy loop. Here is my code:
'Count paragraphs, sentences, and words.
Sub CountWordSentPar
Dim oCursor
Dim nPars As Long
Dim nSentences As Long
Dim nWords As Long
If Not Globalscope.BasicLibraries.isLibraryLoaded("MRILib") Then
Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
End If
oMRI = CreateUnoService("mytools.Mri")
REM Create a text cursor.
oCursor = ThisComponent.Text.createTextCursor()
oCursor.gotoStart(False)
Do
nPars = nPars + 1
Loop While oCursor.gotoNextParagraph(False)
oCursor.gotoStart(False)
Do
nSentences = nSentences + 1
Loop While oCursor.gotoNextSentence(False)
oCursor.gotoStart(False)
Do
nWords = nWords + 1
Loop While oCursor.gotoNextWord(False)
MsgBox "Paragraphs: " & nPars & CHR$(10) &_
"Sentences: " & nSentences & CHR$(10) &_
"Words: " & nWords & CHR$(10), 0, "Doc Statistics"
End Sub
I have run this code over the Basic Programmer’s Guide and over a document of my own and, in each case, gotonextsentence goes into a loop, so is clearly not advancing as per the manual.
Can anyone suggest a solution?
Kind regards,
Doug