[Solved] Textbox calculations in Writer template

Keyboard macros or custom scripts

[Solved] Textbox calculations in Writer template

Postby streub » Sat Aug 26, 2017 8:46 pm

I am using Writer for a price tag template.

I have three textboxes involved in the calculation.

Textbox "PCT" will display the value of the completed calculation.

Textbox "RET" is the retail price of an item. The user enters this information.

Textbox "DIS" is the discounted price of an item. The user enters this information.

The calculation is as follows:

PCT = RET - DIS / RET

I have looked throughout the forum but have not located any help with this.

Anybody willing to offer some advice or direction?

I am at ground zero with Basic and UNO.

Thank you

Streub
Last edited by streub on Wed Aug 30, 2017 8:03 pm, edited 1 time in total.
Streub

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

Re: textbox calculations in Writer template

Postby keme » Sun Aug 27, 2017 8:48 am

Does it have to be a textbox, and/or controlled by a macro?

Tables in Writer have simple calculation abilities. You can do it in one table with 3 cells, or in 3 separate 1x1 "tables".

See attached file. If you need to position the tables freely, you can have them inside separate frames.
Attachments
tablecalculations.odt
(9.38 KiB) Downloaded 32 times
User avatar
keme
Volunteer
 
Posts: 2700
Joined: Wed Nov 28, 2007 10:27 am
Location: Egersund, Norway

Re: textbox calculations in Writer template

Postby streub » Sun Aug 27, 2017 5:50 pm

The use of tables is an excellent suggestion. I will attempt to use as you had suggested and will
inform you of the results.

Thank you
Streub

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

Re: textbox calculations in Writer template

Postby streub » Mon Aug 28, 2017 4:14 pm

I did try your suggestion of using frames and tables. It performed as needed; however, this method will not allow me to set a tab order as a textbox object can. Good idea.

Thank you
Streub

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

Re: textbox calculations iand textbox format

Postby streub » Wed Aug 30, 2017 7:06 pm

The code below will calculate the vales of two textboxes and enter the results into a third.
The textbox with the result needs to be formatted to a percentage via macro. I cannot recall
how to do that.

Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****


Sub oPct

oDoc = ThisComponent
oDocView = oDoc.getCurrentController()

   oForm = oDoc.drawpage.forms(0)
      tbp = oForm.getbyname("tbp")
      tbr = oForm.getbyname("tbr")
      tbd = oForm.getbyname("tbd")
   
      tbp.text  = (tbr.value - tbd.value) / tbr.value
      
      
   
   



End Sub



Streub

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

Re: textbox calculations in Writer template

Postby robleyd » Thu Aug 31, 2017 1:12 am

Alternatively you could create a string in percentage format - something like
Code: Select all   Expand viewCollapse view
tbp.text  = ((tbr.value - tbd.value) / tbr.value) * 100 & "%"


Note: I don't use macros myself, so syntax for the concatenation operator may be wrong :)
Cheers
David
Apache OpenOffice 4.1.4 - Windows 7
Apache OpenOffice 4.1.5 - Slackware 14.2 - 64 bit
User avatar
robleyd
Moderator
 
Posts: 1212
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 6 guests