[Solved] Format textbox as percentage

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

[Solved] Format textbox as percentage

Post by streub »

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

this is what I have thus far:

Code: Select all

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
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Format textbox as percentage

Post by Zizi64 »

What about the function TEXT:

Code: Select all

tbp.text  = Format((tbr.value - tbd.value) / tbr.value * 100,"0.00")&"%"
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
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
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Format textbox as percentage

Post by Villeroy »

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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
streub
Posts: 128
Joined: Thu Jan 02, 2014 2:48 am
Location: Wisconsin

Re: Format textbox as percentage

Post by streub »

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
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Format textbox as percentage

Post by Zizi64 »

Please upload your ODF type sample file here together with the embedded macro.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
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.
streub
Posts: 128
Joined: Thu Jan 02, 2014 2:48 am
Location: Wisconsin

Re: Format textbox as percentage

Post by streub »

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
Post Reply