Pixels to Twips

By | 2002-06-01

This converts pixels to twips

Original Author: unknown

Inputs

# of Pixels or twips

Assumptions

This converts pixels to twips, if you get the rect of a window it’s in pixels, to make your form that size you need to convert the pixels to twips.
As someone pointed out in one of my other submisions, it might be a little faster to take away the function and just use the insides where needed but i find the function saves some typing and makes the code easier to read.

Returns

# of pixels or twips… see code

Code

Function PixelsToTwips_height(pxls)
PixelsToTwips_height = pxls * screen.TwipsPerPixelY
end function
Function PixelsToTwips_width(pxls)
PixelsToTwips_width = pxls * screen.TwipsPerPixelX
end function
'This next part reverses the las although you should
'be able to use basic math
Function TwipsToPixels_height(pxls)
PixelsToTwips_height = pxls screen.TwipsPerPixelY
end function
Function TwipsToPixels_width(pxls)
PixelsToTwips_width = pxls screen.TwipsPerPixelX
end function

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.