Macro will not execute consistently

Creating a macro - Writing a Script - Using the API

Macro will not execute consistently

Postby streub » Sun Oct 29, 2017 12:22 am

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.

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

The file is too large to attach.

Thank you in advance for the assistance.


The more I learn from this forum, the more I get excited about using this strange application
Posts: 128
Joined: Thu Jan 02, 2014 2:48 am
Location: Wisconsin

Re: Macro will not execute consistently

Postby UnklDonald418 » Sun Oct 29, 2017 7:08 pm

Debugging a “macro does not execute consistently ” is difficult. Out of context, nearly impossible.
I would add a line
Code: Select all   Expand viewCollapse view
temp = (tbr.value - tbd.value) / tbr.value * 100

just before
Code: Select all   Expand viewCollapse view
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.6 & LibreOffice - Windows 10 Professional
Posts: 1007
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Macro will not execute consistently

Postby Villeroy » Sun Oct 29, 2017 7:55 pm

Code: Select all   Expand viewCollapse view
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, OpenOffice 4.x & LibreOffice 6.x
User avatar
Posts: 26136
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 10 guests