Page 1 of 1

[Solved] Format textbox as percentage

Posted: Wed Aug 30, 2017 8:06 pm
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


Re: Format textbox as percentage

Posted: Wed Aug 30, 2017 9:46 pm
by Zizi64
What about the function TEXT:

Code: Select all

tbp.text  = Format((tbr.value - tbd.value) / tbr.value * 100,"0.00")&"%"

Re: Format textbox as percentage

Posted: Wed Aug 30, 2017 10:14 pm
by Villeroy
A text box has no number formats. A numeric field or formatted field has.

Re: Format textbox as percentage

Posted: Wed Aug 30, 2017 11:03 pm
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

Re: Format textbox as percentage

Posted: Thu Aug 31, 2017 6:57 am
by Zizi64
Please upload your ODF type sample file here together with the embedded macro.

Re: Format textbox as percentage

Posted: Sun Sep 10, 2017 10:34 pm
by streub
Issue resolved using Calc and formulas.

Thank you all.