copyByName of sheet triggers modifyListener, runtime error

Creating a macro - Writing a Script - Using the API

copyByName of sheet triggers modifyListener, runtime error

Postby Ron_H » Tue Sep 10, 2019 5:01 pm

I have a sub that causes a runtime error when it tries to create a copy of an existing sheet.
This code has worked.

With the debugger (and prior to the error), I have found:

[*] newSheetName and newSheetNum look good before the call to copyByName
[*] I get many calls to "com.sun.star.util.XModifyListener" while copyByName is running (I put break points in the call back, "sub StepMode_modified(event as object)"

Here's the code that creates the listeners.
Code: Select all   Expand viewCollapse view
Sub StepModeListenerOn

   Cycle_Steps = ThisComponent.Sheets.getByName("Cycle_Steps")
   oRange = Cycle_Steps.getCellRangebyName("C6:c171")
      oListener = createUnoListener("StepMode_", "com.sun.star.util.XModifyListener")
   
   for steppe = 1 to 166
      oCell = oRange.getCellByPosition(0,steppe-1)
      oCell.addModifyListener(oListener)
   
   next steppe

End Sub

Here's the code up to the call that throws the error...
Code: Select all   Expand viewCollapse view
sub stepAlarmButton(eventer as object)
   True = -1
   False = 0
   doc=ThisComponent
   sheet=Doc.CurrentController.ActiveSheet
   sheetName = sheet.spreadsheet.name
   
   if sheetName = "SA_Template" then
      dim pointName as string
      SA_Template = ThisComponent.Sheets().getByName("SA_Template")
      CellRange = SA_Template.getCellRangeByPosition(0,0,4,4)
      Descript = CellRange.createSearchDescriptor()
      Descript.SearchString = "Input"
      Descript.SearchWords = False 'If true, the search will match only complete words
      Cell = CellRange.findFirst(Descript)
      pointNameCell = SA_Template.getCellByPosition(Cell.CellAddress.column+1, cell.CellAddress.row)
      pointName = pointNameCell.string
      newSheetName = "SA_" & pointName
      
      if pointExists(pointName) then
         sheetIs = sheetExists(newSheetName)
         
         if not sheetIs then
            newSheetNum = SA_Template.rangeAddress.sheet + 1
            document = thiscomponent
            document.getSheets().copyByName("SA_Template",newSheetName,newSheetNum)


The error message says...
BASIC runtime error.
An exception occured.
Type: com.sun.star.uno.RuntimeException
Message: .

That's right: the message is a period.

What do you think?
What else would you like to know?
Thanks!
OpenOffice 3.2 on Windows XP Pro and 3.? Suse
Ron_H
 
Posts: 16
Joined: Tue Jul 06, 2010 4:20 pm

Re: copyByName of sheet triggers modifyListener, runtime err

Postby JeJe » Tue Sep 10, 2019 10:25 pm

I suggest you upload the document. For anyone to look at this they have to do a lot of work first... add 3 end ifs in the second routine, create a Sheet called "SA_Template" and so on.

Don't use variables or constants called True and False - They're reserved words for the boolean True and False. This is not good:

True = -1
False = 0
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 582
Joined: Wed Mar 09, 2016 2:40 pm

Re: copyByName of sheet triggers modifyListener, runtime err

Postby Ron_H » Wed Sep 11, 2019 12:28 am

JeJe,
Sorry and thanks. You are right.

I'll try to create an example - I don't think I should upload the document.
I thought perhaps the fact that copyByName appears to be generating events in a completely different sheet would make someone say woah.
But, even if it is - still need the example.
https://en.wikipedia.org/wiki/Minimal_working_example

Thanks for the info on True and False. Odd I have to be told by a person.
Seems like something the program would complain about.
OpenOffice 3.2 on Windows XP Pro and 3.? Suse
Ron_H
 
Posts: 16
Joined: Tue Jul 06, 2010 4:20 pm

Re: copyByName of sheet triggers modifyListener, runtime err

Postby JeJe » Wed Sep 11, 2019 1:22 am

It did complain about it when I copied and pasted your code... I presume you've declared them as variables outside the code you've pasted.

Looking at your last line - that will give that error message if newSheetNum is a negative number or a sheet called newSheetName already exists.

Try putting a number in instead of the variable and see if everything works. Take a look at this line and see what its giving you

newSheetNum = SA_Template.rangeAddress.sheet + 1

Make sure the sheet doesn't already exist.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 582
Joined: Wed Mar 09, 2016 2:40 pm

Re: copyByName of sheet triggers modifyListener, runtime err

Postby Ron_H » Sun Sep 22, 2019 5:55 pm

JeJe,

Thanks for pointing out true &false are keywords and shouldn't be used otherwise.

I have removed declarations of and assignments to True and False in a few instances of the code.
I don't think I have seen the error from any of these instances after making the changes.

I will mark solved after I get a bit more confident.
OpenOffice 3.2 on Windows XP Pro and 3.? Suse
Ron_H
 
Posts: 16
Joined: Tue Jul 06, 2010 4:20 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 8 guests