Macro will not execute consistently

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
streub
Posts: 128
Joined: Thu Jan 02, 2014 2:48 am
Location: Wisconsin

Macro will not execute consistently

Post by streub »

I am using this macro to calculate the percentage savings on a template. The macro does not execute consistently and the percent formatted control does not always display the percentage (%) symbol. I have used several events but with no success.

Code: Select all

REM  *****  BASIC  *****


Sub oPct

	oDoc = ThisComponent'Clearance Tag
	oDocView = oDoc.getCurrentController()

	oForm = oDoc.drawpage.forms(0)

		tbp = oForm.getbyname("tbp")'percent discount
		tbr = oForm.getbyname("tbr")'retail price
		tbd = oForm.getbyname("tbd")'discounted price
		
		tbp.text  = (tbr.value - tbd.value) / tbr.value *  100
		
End Sub
[code]

The file is too large to attach.

Thank you in advance for the assistance.

Streub
Streub

The more I learn from this forum, the more I get excited about using this strange application
UnklDonald418
Volunteer
Posts: 1546
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Macro will not execute consistently

Post by UnklDonald418 »

Debugging a “macro does not execute consistently ” is difficult. Out of context, nearly impossible.
I would add a line

Code: Select all

temp = (tbr.value - tbd.value) / tbr.value * 100 
just before

Code: Select all

tbp.text = (tbr.value - tbd.value) / tbr.value * 100 
In the IDE set a break point on the second line and a watch on the variable temp.
If the macro fails to execute then you know the problem is definitely Event related.
If the value shown for temp isn't what you expect, then you will need to watch the values used in the calculation.
If, when using the IDE with the break point, the macro always works you could try inserting a delay something like Wait 200 just before the second line above.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro will not execute consistently

Post by Villeroy »

Code: Select all

x = tbr.value
y = tbd.value
temp = (x - y) / x

REM if tbp happens to be a formattable control for numeric content
REM you can format that thing as percent value and set its numeric value
tbp.Value = temp 
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply