Page 1 of 1

copyByName of sheet triggers modifyListener, runtime error

Posted: Tue Sep 10, 2019 5:01 pm
by Ron_H
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

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

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!

Re: copyByName of sheet triggers modifyListener, runtime err

Posted: Tue Sep 10, 2019 10:25 pm
by JeJe
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

Re: copyByName of sheet triggers modifyListener, runtime err

Posted: Wed Sep 11, 2019 12:28 am
by Ron_H
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.

Re: copyByName of sheet triggers modifyListener, runtime err

Posted: Wed Sep 11, 2019 1:22 am
by JeJe
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.

Re: copyByName of sheet triggers modifyListener, runtime err

Posted: Sun Sep 22, 2019 5:55 pm
by Ron_H
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.