Results 1 to 13 of 13

Thread: Millimeters to Twips

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Location
    Brazil
    Posts
    65

    Millimeters to Twips

    Hello all,

    i need a function to convert millimeters to twips.

    i have found some functions to convert twips in pixels, but i don't know how to convert milimeters in twips or pixels.


    Thanks!

  2. #2
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    You can use a trick like, place a picturebox and then:
    VB Code:
    1. Option Explicit
    2. Private Sub Form_Click()
    3.     Dim x As Single
    4.     Dim y As Single
    5.     picture1.ScaleMode = vbTwips
    6.     x = picture1.ScaleWidth
    7.     picture1.ScaleMode = vbMillimeters
    8.     y = picture1.ScaleWidth
    9. End Sub
    so that x twips correspond to y mm
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  3. #3
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    mm does not relate to twips equally on differently sized monitors.

    For example, the twip to mm conversion might be 220 on a 15" monitor and 250 on a 17" monitor, etc...

  4. #4
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    Originally posted by Dave Sell
    mm does not relate to twips equally on differently sized monitors.

    For example, the twip to mm conversion might be 220 on a 15" monitor and 250 on a 17" monitor, etc...
    That is true. But is really impossible to make an actual twips to life-size millimeter, this is because every monitor is different. If you don't have a flat monitor yet, you have buttons to change the width and height of the size of the image that is being put on your screen. Just changing that, makes a millimeter more or less twips. Due to this kind of ways of changing the distance between two pixels (and therefore between twips) it is actually impossible to make a piece of code that convert twips to millimeters correctly.
    No matter how fool-proof your program is, there will always be a better fool.

    Was a post helpful to you? Rate it!

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Twips are a standard measurement, regardless of the monitor resolution and size.

    1440 Twips/Inch
    25.4 MM/Inch

    56.7 Twips/MM

  6. #6
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    Originally posted by arsmakman
    it is actually impossible to make a piece of code that convert twips to millimeters correctly.
    I think that may be a false statement; but I think you have to get the correct conversion at run-time, because it definately would be impossible to get it at design time.

    I had to do this once - I'll see if I can dig up how I did it. I believe it may have been a series of API calls.

  7. #7
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    Originally posted by brucevde
    Twips are a standard measurement, regardless of the monitor resolution and size.

    1440 Twips/Inch
    25.4 MM/Inch

    56.7 Twips/MM
    I think those are only fixed for printed media, not monitor media. I can swear that getting the mm-twip conversion for the monitor screen is not fixed.

  8. #8
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    OK it's been a while, but as I recall, this is what I did before:

    Consider a monitor. How is the resolution defined? By inches or milimeters? Nope. By pixels. You basically want to design your GUI based on a certain resolution like 800x600, 1024x768 or whatever.

    Those figures are given in units of pixels.

    So, in VB, you want your GUI to remain proportional with respect to the screen, which is given in pixels. But! VB does not use pixels when manipulating controls by default. VB uses twips.

    Thus, you must get the run-time conversion factor of twips to pixels. To do this, you must use the following functions:

    VB Code:
    1. TwipsPerPixelX
    and
    VB Code:
    1. TwipsPerPixelY

    Those function calls will yeild different values depending on monitor size and screen resolution, and thus must be used at run-time only.

    Looking back to brucevde's post, he gave some fixed values. Those values are fixed for printed media only.

  9. #9
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,882
    We use TWIPSPERPIXELx/y all the time - for monitor and printer work.

    Try out this code:

    VB Code:
    1. Public Function ScreenResolution() As String
    2.  
    3. Dim i As Long, j As Long, k As Long, x As Long, y As Long, z As Long
    4. Dim s1 As String, s2 As String, s3 As String, s4 As String, s5 As String
    5.  
    6. Debug.Print "   ScreenResolution"
    7. On Error GoTo Error_Handler
    8.  
    9. Begin:
    10.     i = Screen.Width
    11.     j = Screen.TwipsPerPixelX
    12.     k = i \ j
    13.     x = Screen.Height
    14.     y = Screen.TwipsPerPixelY
    15.     z = x \ y
    16.    
    17.     ScreenResolution = CStr(k) & " x " & CStr(z) & " (" & CStr(i) & " @" & CStr(j) & " X " & CStr(x) & " @" & y & ")"
    18.    
    19. Rtn_Caller:
    20.     Exit Function
    21.  
    22. Error_Handler:
    23.     Call Fatal_Error(Err.Number, Err.Source, Err.Description, "ScreenResolution")
    24.     Resume Rtn_Caller
    25.  
    26. End Function

    On my workstation I get:

    "1280 x 1024 (19200 @15 x 15360 @ 15)"

    It is the 15 that is meaningful. If I set something to twip 10, that doesn't exist - it's 0, 15, 30, 45 (and so on) that are available.

    We use TWIP positioning in our print logic - if we didn't keep track of this MOD math, we would have "positions" on paper start slipping a bit as they progressed down the page...

  10. #10
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    The question was - How to convert Millimeters to Twips. This has nothing to do with Pixels.

    Again, regardless of monitor size and resolution, there are 56.7 Twips per MM.
    Last edited by brucevde; Oct 4th, 2004 at 05:50 PM.

  11. #11
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,882
    brucevde - I am in no way looking to challenge your statement...

    TWIPS - from a definition on the net...

    Definition: (TWentIeth of a Point) 1/20 of a Postscript point, or 1/1440th of an inch. There are thus 1440 twips to an inch or about 567 twips to a centimeter.

    Twips are used in Microsoft formats and products, notably Rich Text Format, Visual BASIC, Visual C++, and printer drivers; and in IBM AFP products.

    Twips were devised in the olden days to describe the sizes of characters produced by dot matrix printers that were constrained to multiples of either 12 or 10 dots per inch.
    The original post actually mentioned:

    TWIPS - 3 times
    PIXELS - 2 times
    MILLIMETERS - 2 times

    Since the actual display or printer talks in PIXELS, understanding that everyting else maps to this is important.

    If someone is trying to represent a "real" length in millimeters, than understanding the PIXEL loss and TWIP/PIXEL ratio is truly important...

  12. #12
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,794
    Here's what I did:

    I put a picturebox on the form, with no border
    set the form's ScaleMode to millimiters
    set the picture's with to 10 (10 millimiters)
    changed the form's ScaleMode back to Twips
    the picture's with now is 567 -> 567 / 10 = 56.7 twips per millimiter

    I don't have a ruller around me, but it looks like the right size on the screen i.e. the 10 millimiters I've set, it looks like 1 Centimiter (10 millimiters in 1 centimiter), i'm pretty familiar with metric system (i'm European). So it looks right no me...

    P.S (if it makes any difference) I have 17" LCD monitor with 1280x1024 resolution

  13. #13
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    Originally posted by CVMichael
    Here's what I did:

    I put a picturebox on the form, with no border
    set the form's ScaleMode to millimiters
    set the picture's with to 10 (10 millimiters)
    changed the form's ScaleMode back to Twips
    the picture's with now is 567 -> 567 / 10 = 56.7 twips per millimiter
    Right, that's pretty much what I suggested in the thread's 2nd post way up there.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width