| View previous topic :: View next topic |
| Author |
Message |
timecop Power User

Joined: 04 Mar 2005 Posts: 66 Location: Philippines
|
Posted: Mon Feb 27, 2006 3:40 am Post subject: How do I know if the cursor is in the table? |
|
|
Hi All,
I have a code that will search the occurences of a number and a letter([a-z]) then insert a string to it. My problem is everytime the search words is in the tables or in the footnotes, it throws an error. My idea in mind is that, everytime there is a match, I will check if it is in the table or footnotes, then I will create another cursor just for them. But my problem is how do I know if the cursor is in the table or in the footnotes? Please help or any suggestions.
Here is my code:
| Code: |
Sub CheckUnits
Dim oDescriptor
Dim oFound
oDescriptor = ThisComponent.createSearchDescriptor()
oDescriptor.SearchString = "\<([:digit:]+)[a-z]"
oDescriptor.SearchRegularExpression = True
oFound = ThisComponent.findFirst(oDescriptor)
Do While Not IsNull(oFound)
oCursor = oFound.Text.createTextCursorByRange(oFound)
oView = ThisComponent.getCurrentController().getViewCursor()
oView.gotoRange( oCursor, False )
If Msgbox ("Do you want to insert a non-breaking space between this number and unit?", 36, "Confirm") = 6 Then
sData = oCursor.getString()
num = Mid(sData, 1, len(sData)-1 )
units = Right(sData, 1)
oCursor.setString("")
ThisComponent.Text.insertString(oCursor, num & CHR$(32) & units, False)
oFound = ThisComponent.findNext( oFound.end, oDescriptor )
Else
oFound = ThisComponent.findNext( oFound.end, oDescriptor )
End If
Loop
End Sub
|
_________________ Time is Gold |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Mon Feb 27, 2006 11:15 am Post subject: |
|
|
I discuss this in my free macro document (at least I think that I do... I know that I discuss this in my book).
Which line generates the error?
| Code: | Sub CheckUnits
Dim oDescriptor
Dim oFound
oDescriptor = ThisComponent.createSearchDescriptor()
oDescriptor.SearchString = "\<([:digit:]+)[a-z]"
oDescriptor.SearchRegularExpression = True
oFound = ThisComponent.findFirst(oDescriptor)
Do While Not IsNull(oFound)
REM Does this line fail?
oCursor = oFound.Text.createTextCursorByRange(oFound)
oView = ThisComponent.getCurrentController().getViewCursor()
oView.gotoRange( oCursor, False )
If Msgbox ("Do you want to insert a non-breaking space between this number and unit?", 36, "Confirm") = 6 Then
sData = oCursor.getString()
num = Mid(sData, 1, len(sData)-1 )
units = Right(sData, 1)
oCursor.setString("")
REM YOUR PROBLEM IS HERE
REM ThisComponent.Text.insertString(oCursor, num & CHR$(32) & units, False)
REM Does this fix the problem?
oFound.Text.insertString(oCursor, num & CHR$(32) & units, False)
oFound = ThisComponent.findNext( oFound.end, oDescriptor )
Else
oFound = ThisComponent.findNext( oFound.end, oDescriptor )
End If
Loop
End Sub |
_________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
timecop Power User

Joined: 04 Mar 2005 Posts: 66 Location: Philippines
|
Posted: Mon Feb 27, 2006 10:37 pm Post subject: |
|
|
Hi Andrew, this line:
| Code: |
oFound.Text.insertString(oCursor, num & CHR$(32) & units, False)
|
solved my problems. Thanks a lot. _________________ Time is Gold |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|