Seems a desperately simple question but I'm flummoxed! OE 10.2B.
I'm using a form to display text on a report. I've had to add a variable to make it more generic, but the text isn't centralised as it's placed on the form based on the format of the variable.
Here's the code.
form skip(3) CurrentCompany at 77 skip 'Weekly Stock Sheet' at 88 skip(2) 'Customer: ' at 2 customer.customer customer.cust-name skip 'Date From: ' at 2 vd-date-from format '99/99/9999' ' Date To:' vd-date-to format '99/99/9999' skip(2) 'Product Product Weeks In Cartons Pallets Cartons Pallets Cartons Pallets Cartons Pallets Cartons Pallets' at 2 skip 'Code Description WHSE C/FWD C/FWD In In Out Out Adj Adj Balance Balance' at 2 skip '__________________________________________________________________________________________________________________________________________________________________' at 2 With Column 1 Row 1 Overlay width 200 no-box 1 Down no-labels no-attr-space STREAM-IO use-text frame head-goodsin.
I want CurrentCompany to be justified centrally, but when it's quite a short name it's way over on the left. Any ideas?
I've worked it out by calculating the length of the text, and padding it based on the format.
the general formula for centering text (horizontally) goes like this:
newXPos = oldXPos + (FieldWidth - TextLength) / 2
This should work with character and graphical layout. I use this all the time with Form, Report, and Label output in our ERP system.
BTW: to right-justify, just remove the /2 at the end.
That works for fixed fonts. Proportional fonts require a bit more work with the font table.
It depends on how you look at it.
Assuming we're working in a system like dots, twips, or inches, replace "TextLength" with "TextWidth". Just make sure all the variables are in the same units.
There are Windows API functions and .Net methods that can measure the width of a piece of text given the font used.
Just use the don’t-table handle attributes and methods.