I'm using OOo 2.4.0 on Win XP, I'm also fairly new to coding OOo Basic while having plenty of VBA experience.
What I do
The relevant Basic code searches in a selected text for a regular expression and replaces the found occurances with underscores. This is the relevant code snippet:
Code: Select all
'... declaration of oSearch, oTextRange (created by range from oSelection.getByIndex(i)), oDocument, etc. ...
oFound = oDocument.findNext(oTextRange.getStart(), oSearch)
do while not IsNull(oFound)
'ERROR OCCURS IN THE NEXT LINE:
if oTextRange.getText().compareRegionEnds(oFound, oTextRange.getEnd()) = -1 then exit do
oFound.setString(String(Len(oFound.getString()), "_"))
oFound = oDocument.findNext(oFound.getEnd(), oSearch)
loop
The code works fine, except in certain exotic circumstances: The marked line of code triggers an IllegalArgumentException (no Message) only if oTextRange is such that it
- a) contains the last or next to last character of any text in a table cell which is not the last table cell (and not the only table cell in a table with only one cell),
- b) contains the last or next to last character of text in a document which anywhere contains an anchor for a textframe.
Does anyone recognize this behaviour and knows how to fix or avoid it? I cannot make sure in advance that the working document contains no tables, textframes, etc. and I want the replace to work in as many scenarios (different types/positions of selected text) as possible.
Thanks! Tyll