Results 1 to 2 of 2

Thread: Why PrintDocument Margins Wrong on Printed Paper ?

Threaded View

  1. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Why PrintDocument Margins Wrong on Printed Paper ?

    Quote Originally Posted by Nicomendox View Post
    I am not rounding any margin value.
    Oh yes you are.
    Quote Originally Posted by Nicomendox View Post
    Used Math.Truncate(number) to disable Round.
    But you used it wrong, so it is actually rounding toward zero. Example:
    vb.net Code:
    1. hght = Math.Truncate(((33.9) * 100) / 100)
    If we exapnd that out it becomes this:
    vb.net Code:
    1. Dim a = 33.9
    2. Dim b = (a) * 100 'a = 339.0
    3. Dim c = (b) / 100 'b = 33.9
    4.  
    5. hght = Math.Truncate(c) 'hght = 33.0
    What you actually should be doing is this:
    vb.net Code:
    1. Dim a = 33.9
    2. Dim b = (a) * 100 'a = 339.0
    3. Dim c = Math.Truncate(b) 'c = 339.0
    4.  
    5. hght = (c) / 100 'hght = 33.9
    If you hadn't included so many useless parentheses then you wouldn't have missed the wood for the trees:
    vb.net Code:
    1. hght = Math.Truncate(33.9 * 100) / 100
    You should have been able to work this out for yourself because you should have done exactly what I did , i.e. expanded the single lines that performed multiple operations into multiple lines that performed a single operation each. Had you done that and actually debugged the code, the issue would have been obvious.

    Of course, if you're using literal values then why is any of that being used at all? 33.9 is 33.9, whether it's a literal or the result of a calculation. What do you think that that code is accomplishing?
    vb.net Code:
    1. hght = 33.9D
    Just use a Decimal literal in the first place. You also must have Option Strict Off or else assigning a Double to a Decimal variable, as you are doing, would not be allowed. Turn Option Strict On in the project and the IDE and use Decimal literals where you need Decimal values.
    Last edited by jmcilhinney; Apr 19th, 2020 at 12:03 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

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