Tech Articles


PowerBuilder 'Gotcha' - PixelsToUnits


From the 12.5 Powerbuilder Help on this method:
Converts pixels to PowerBuilder units. Because pixels are not usually square, you also specify whether you are converting the pixels' horizontal or vertical measurement.

Syntax

PixelsToUnits ( pixels, type )

Argument Description
pixels An integer whose value is the number of pixels you want to convert to PowerBuilder units.
type A value of the ConvertType enumerated datatype value indicating how to convert the value:
· XPixelsToUnits! - Convert the pixels in the horizontal direction.
· YPixelsToUnits! - Convert the pixels in the vertical direction.
Return value

Integer. Returns the converted value if it succeeds and -1 if an error occurs. If any argument's value is null, PixelsToUnits returns null.

Note the return value of integer. If you are using this method to say, calculate the width of a string field, the results can easily exceed the maximum value of a Powerbuilder integer which is 32767. To correct for this you will need to do something like:.

integer li_width, li_width_factor
long ll_width
// calculate the width of a single pixel
li_width_factor = PixelsToUnits(1, XPixelsToUnits!) 
// use the calculated factor to obtain the actual width of a very wide string column
ll_width = li_width * li_width_factor //li width is width in pixels
Comments (1)
Monday, Mar 20 2017

Hi Matt;

   Great tip!

FYI ... also, don't forget you can use the Appeon Web/Mobile calculator as well located on the Appeon Developer toolbar ... 

<img alt="Appeon PBU => Pixel Calculator " src="/sites/default/files/inline-images/Appeon_Calculator.png" />

 

Regards .... Chris

#2
0

Find Articles by Tag

PostgreSQL Export .NET Assembly PDF Web API JSONParser Error Filter Excel RESTClient Authorization Mobile PFC SQL Transaction UI Modernization Deployment InfoMaker Sort Automated Testing PowerBuilder API Database Table Debugging OrcaScript CI/CD Bug HTTPClient Model Event Application Source Control Messagging Database Connection Configuration IDE Database Profile Database Object SnapDevelop Debugger MessageBox Service OAuth Jenkins Source Code Oracle TLS/SSL ActiveX PBDOM DataWindow JSON Design PowerServer Mobile REST Script RibbonBar Builder PowerBuilder Compiler Window RichTextEdit Control Performance Interface SnapObjects Migration PowerBuilder (Appeon) XML DragDrop Variable Installation Resize Array TreeView PDFlib BLOB Data Graph Windows OS .NET Std Framework Outlook Elevate Conference DLL Linux OS Charts Testing License 32-bit 64-bit WinAPI Syntax PostgreSQL ODBC driver Expression Export JSON Menu SqlExecutor Android RibbonBar Validation Encoding SqlModelMapper JSONGenerator Repository COM TFS External Functions GhostScript SDK Database Table Schema Windows 10 Icons CoderObject Authentication iOS PowerScript (PS) CrypterObject Database Stored Procedure Branch & Merge NativePDF TortoiseGit Encryption Azure OAuth 2.0 UI Themes WebBrowser SQL Server Import JSON ODBC DataWindow UI DevOps C# Text File Web Service Proxy Platform DataType Open Source SVN Event Handler SOAP OLE .NET DataStore Import JSON Debug Database Table Data Icon Git Event Handling Database Painter Trial PowerServer Web Class