Cursor.gotonextsentence failing

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

I forgot to mention I am running LibreOffice 5.2.3.3

It seems the .gotoNextSentence(False) method does not return False at the End of Document.

Here a solution in python for counting Sentences and Paragraphs.

def count_Paras_and_sentences():
    doc = XSCRIPTCONTEXT.getDocument()
    cursor = doc.Text.createTextCursor()
    cursor.gotoStart(False)
    sentencecount = 0
    paracount = 0
    while True:
        sentencecount += 1
        cursor.gotoNextSentence( False )
        cursor.gotoEndOfSentence( False )
        if cursor.isEndOfParagraph():
            paracount += 1
            if not cursor.gotoNextParagraph( False ):
                return paracount, sentencecount

Edit: the same more pythonic-Style:

def count_Sentences(cursor, count=0):
    while not cursor.isEndOfParagraph():
        count += 1
        cursor.gotoNextSentence( False )
        cursor.gotoEndOfSentence( False )
    return count




def count_Paras_and_sentences():    
    doc = XSCRIPTCONTEXT.getDocument()
    cursor = doc.Text.createTextCursor()
    cursor.gotoStart(False)
    sentencecount = 0
    paracount = 0
    while cursor.gotoNextParagraph(False):
        sentencecount += count_Sentences(cursor, sentencecount)
        paracount += 1

    return paracount, sentencecount

Interesting, because in my experience neither of the solutions work. I had tried something similar before finding this piece of code. It did not work. After finding it, I tried both versions. Neither worked. How come this issue is closed?
Finding the next paragraph is ok. At the end of the document, False is returned. But, as to nextsentence, it does not work. (Neither does next word).

For example: the following text results in 12 sentences, but it should yield 14:

One. Two. Three. Four. Five.
Six. Seven. Eight. Nine.
Ten. Eleven. Twelve.
Thirteen. Fourteen.