Page 1 of 1

[Solved] How to tell where my ViewCursor is currently at?

PostPosted: Sun Jun 17, 2012 12:59 am
by mlsoong
Hi
I am new to this forum and had tried to find a solution to my problem
Am writing a macro to read line by line of a document in Writer until the end of the document. I put into a loop a dispatcher goDown, then a dispatcher EndOfLineSel to read the line with the viewcursor.getstring. How do I know that I have finished reading the last line? Does the goDown dispatcher return a "I am at EndOfDocument" flag or if the cursor has a "atEndOfDocument" flag?
Thanks & Regards
mlsoong

Re: How to tell where my viewcursor is currently at?

PostPosted: Sun Jun 17, 2012 1:35 am
by FJCC
I would use the compareRegionEnds() method of the Text object of the document.
Code: Select all   Expand viewCollapse view
oText = ThisComponent.Text
VCurs = ThisComponent.CurrentController.ViewCursor
VCurs.gotoStart(False)  'move to start of document
VCurs.gotoEndOfLine(True)
Print VCurs.String
While oText.compareRegionEnds(VCurs.End, oText.End) <> 0  ' will = 0 when the Cursor.End is on top of the Text.End
   VCurs.goDown(1, False)
   VCurs.gotoStartOfLine(False)
   VCurs.gotoEndOfLine(True)
Print VCurs.String
Wend

Re: [Solved] How to tell where my viewcursor is currently at

PostPosted: Sun Jun 17, 2012 3:33 am
by mlsoong
Thanks FJCC. It is exactly what I need, and it works like a charm.