OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How do I know if the cursor is in the table?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
timecop
Power User
Power User


Joined: 04 Mar 2005
Posts: 66
Location: Philippines

PostPosted: Mon Feb 27, 2006 3:40 am    Post subject: How do I know if the cursor is in the table? Reply with quote

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
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Mon Feb 27, 2006 11:15 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address
timecop
Power User
Power User


Joined: 04 Mar 2005
Posts: 66
Location: Philippines

PostPosted: Mon Feb 27, 2006 10:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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