by SPY-3 (5 Submissions)
Category: Coding Standards
Compatability: VB Script
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)
Here is a real simple way to convert the size of vb(twips) into pixels.
I found that if you want to convert the vb size(twips) into pixels simply do this
(of course change vbsize to how large the control is ex 495)
Pixels = vbsize / Screen.TwipsPerPixelX or Y
To turn pixels into vb
(Change pixels into how many pixels ex 33)
VB = pixels * Screen.TwipsPerPixelX or Y
Examples:
txtPixelHeight.Text = 495 / Screen.TwipsPerPixelX or Y
Me.Height = 33 * Screen.TwipsPerPixelX or Y
Also here is a simple function to turn twips to pixels,
Public Function TwipsToPixel(Twips As Integer, XorY As Boolean) As Integer
If XorY = True Then
TwipsToPixel = Twips / Screen.TwipsPerPixelX
Else
TwipsToPixel = Twips / Screen.TwipsPerPixelY
End If
End Function
Here is a function to turn Pixels To Twips,
Public Function PixelToTwips(Pixels As Integer, XorY As Boolean) As Integer
If XorY = True Then
PixelToTwips = Pixels * Screen.TwipsPerPixelX
Else
PixelToTwips = Pixels * Screen.TwipsPerPixelY
End If
End Function
Hope this helps and please vote.
You are free to change or modify this code however you want.