[Solved] Format textbox as percentage

Creating a macro - Writing a Script - Using the API

[Solved] Format textbox as percentage

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

I not sure how to format a textbox value for percentage.

this is what I have thus far:
Code: Select all   Expand viewCollapse view
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 * 100
      tbp.text format ("percent")
      
      
   
   



End Sub

Last edited by streub on Sun Sep 10, 2017 10:36 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: Format textbox as percentage

Postby Zizi64 » Wed Aug 30, 2017 9:46 pm

What about the function TEXT:

Code: Select all   Expand viewCollapse view
tbp.text  = Format((tbr.value - tbd.value) / tbr.value * 100,"0.00")&"%"
Tibor Kovacs, Hungary; LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.5; AOO4.1.6
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 8235
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Format textbox as percentage

Postby Villeroy » Wed Aug 30, 2017 10:14 pm

A text box has no number formats. A numeric field or formatted field has.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27114
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Format textbox as percentage

Postby streub » Wed Aug 30, 2017 11:03 pm

You are correct! I should have stated it is a field formatted as percent.

The formatting is functioning however the value is displayed as whole number with decimals until I bring focus to that field and depress "ENTER".
The field then rounds up to the nearest whole number.

Suggestions?

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: Format textbox as percentage

Postby Zizi64 » Thu Aug 31, 2017 6:57 am

Please upload your ODF type sample file here together with the embedded macro.
Tibor Kovacs, Hungary; LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.5; AOO4.1.6
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 8235
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Format textbox as percentage

Postby streub » Sun Sep 10, 2017 10:34 pm

Issue resolved using Calc and formulas.

Thank you all.
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


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 6 guests