December 11th, 2006

Sybase PowerBuilder Units to Pixels conversion

I’ve had a sticky note on my cube wall for almost a year now, but it keeps falling off, and the information is not useful in my everyday work now anyways, so I decided to post it here and throw the sticky note away.

First, the formulas:
Pixels (x-axis) = PBU / 4.571429
Pixels (y-axis) = PBU / 4

Second, some 4NT aliases that use the formulas:
pxc=echos %@eval[%@int[%@eval[%1/4.571429]]+
%@if[%@eval[%@int[%@eval[(%1/4.571429-
%@int[%@eval[%1/4.571429]])*100]]] gt 50,1,0]] >clip:

pyc=echos %@eval[%@int[%@eval[%1/4]]+
%@if[%@eval[%@int[%@eval[(%1/4-
%@int[%@eval[%1/4]])*100]]] gt 50,1,0]] >clip:

Finally, an explanation:
I was doing some PowerBuilder to Jasper Reports conversion manually last year, and this meant creating new reports in iReport (a GUI front-end for JasperReports), and creating all the various column headers/data fields/groupings/etc. I could have just eyeballed it, visually comparing the old report to the new one, and being content with “looks about the same”, but I’m a bit too anal for that.

I wanted to make each element the exact same size and place it at the exact same {x, y} coordinates. The problem was that the old version of PowerBuilder I was using would only give me these attributes (width, height, x, y) in some funky unit of measurement called PowerBuilder Units (PBU). I researched PBU for quite a while, hoping to find a formula to make the conversion simple. But, from what I read, these units are designed to adjust to the platform that the report is being created or viewed on, or something like that.

There was a way to make PowerBuilder show me the values in pixels, but it involved a multi-step process with multiple mouse clicks, menu selections, etc. for every element, which was just too annoying. So, I ended up creating a new element in a PowerBuilder report, and giving it dimensions that were powers of 10, so I could then switch to the pixel view one time (for just this one test element), and derive a formula for the unit conversion. I think I created one or two more elements with much higher and much lower values, to make sure the formula was actually linear, and it was.

I ended up coming up with the two formulas (shown above), which I promptly stuck on a sticky note for easy reference. I also made some 4NT aliases (also shown above), to make the calculations more convenient. This allowed me to simply paste the PBU values into my 4NT window, using an alias like: “pxc 375“, and the pixel value would be copied to my clipboard for easy pasting into iReport.

One more thing to note is that, for some reason, some (but not all?!) of the values needed to be reduced to 3/4 scale. I don’t remember exactly why, now, but there was some sort of pattern as to which values required scaling. I had a few more 4NT aliases for these cases:
scale34c=echos %@eval[%@int[%@eval[%1*0.75]]+
%@if[%@eval[%@int[%@eval[(%1*0.75-
%@int[%@eval[%1*0.75]])*100]]] gt 50,1,0]] >clip:

px34=scale34 %@eval[%@int[%@eval[%1/4.571429]]+
%@if[%@eval[%@int[%@eval[(%1/4.571429-
%@int[%@eval[%1/4.571429]])*100]]] gt 50,1,0]]

py34=scale34 %@eval[%@int[%@eval[%1/4]]+
%@if[%@eval[%@int[%@eval[(%1/4-
%@int[%@eval[%1/4]])*100]]] gt 50,1,0]]

I hope this is useful to someone. I wish I could have found these simple formulas posted somewhere last year, even if they required a disclaimer like this one: I will not claim that these formulas are correct in all cases, since I do not completely understand PBUs. But, I can say that they worked for me, for every element on every report that I converted, and the formula was consistent on 3 different machines that I tried it on, which all had different screen resolutions (among other differences).

2 Responses to “Sybase PowerBuilder Units to Pixels conversion”

  1. Clint Says:

    4NT rules!

  2. Torrance S Says:

    Thanks! This will help me alot. I appreciate you putting your sticky note up where I could see it too :)

    -Torrance S

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>