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

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