Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Twip Per Pixel in VBScript!!!!

41 views
Skip to first unread message

Jonathan Got Spammed

unread,
Sep 4, 2001, 4:48:00 PM9/4/01
to
For anyone who has struggled with this, and has not yet determined a
way to do this without writing a component, here is a simple way to
determine how many twips per pixel your screen displays via VBScript.

Function GetTwipsPerPixel()
Dim objOneInchInput
Set objOneInchInput = document.createElement("input")
With objOneInchInput
.id = "txtTwip"
.type = "text"
.style.visibility = "hidden"
.style.width = "1in"
End With
document.body.appendChild objOneInchInput
GetTwipsPerPixel = 1440 / objOneInchInput.offsetWidth
document.body.removeChild objOneInchInput
Set objOneInchInput = Nothing
End Sub

This code simply creates a dynamic html input text box, makes it
hidden, sets it's style width to 1 inch, appends it to the body, and
then, since there are 1440 twips per inch, divides the pixel width of
the input box into 1440. If you are using large fonts, this returns 12
twips per pixel, and if you are using small fonts on your machine, it
returns 15 twips per pixel.

Hope this helps some folks out there. . .

Jonathan

Cowboy

unread,
Sep 4, 2001, 10:29:09 PM9/4/01
to
On 4 Sep 2001 13:48:00 -0700, jonathan....@hcahealthcare.com
(Jonathan Got Spammed) wrote:

I personally do not see the need, but this is one of the more
insteresting routines I have seen. in here in quite some time. Nice
addition, Jonathan.

For those who are not familiar, twips are the unit of measure in
Visual Basic. You will see them if you get into desktop development.


Gregory A. Beamer
MCP: +I, SE, SD, DBA
Author: ADO.NET and XML: ASP.NET on the Edge (3Q 2001)

****************************************************
Think Outside the Box!
****************************************************

marc

unread,
Sep 5, 2001, 4:44:08 AM9/5/01
to
>
> I personally do not see the need, but this is one of the more
> insteresting routines I have seen. in here in quite some time. Nice
> addition, Jonathan.
>
How about using activeX controls, like for example the treeview control...
you will need it there... very nice piece of code Jonathan!

Marc


Jonathan Got Spammed

unread,
Sep 5, 2001, 10:53:34 AM9/5/01
to
"marc" <Sorr...@DirtyMail.com> wrote in message news:<9n4okh$c6c$1...@news1.xs4all.nl>...

Thanks for all the great comments. I originally needed a twip count on
my page for an activeX control. Hopefully in later script releases
Microsoft might expose a built in method or property for this, but in
the meantime, this little function works great.

Thanks again guys for the compliments!

Jonathan

0 new messages