Options

Error on Printing Divided Values

MclarenMclaren Member Posts: 47
edited 2011-10-25 in NAV Three Tier
Hi Guys,


I have to a get a value from Two values. If I want to get X I want to get it like Y/Z. There is an issue. If Y and Z are Zero the X value Prints like "#ERROR". If Both the values are Zero I want to get X also as Zero. Can any one provide me a solution on this. Any help will be appreciated.

Comments

  • Options
    BeliasBelias Member Posts: 2,998
    this is math, not programming...
    example:
    if n <> 0 and m <> 0
    n/m = x

    if n= 0 and m <> 0
    n/m = 0

    if n<>0 and m = 0
    division by zero: impossible

    if n= 0 and m= 0
    zero divided by zero: indefinite (i don't know if it's correct english)

    the correct value for you should be ERROR (mathematically talking), but if you want zero if the division errors out, then just do
    if m <> 0 then
      x := n/m
    else
      x := 0;
    
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    MclarenMclaren Member Posts: 47
    Tx Belias.
    How to write it under Value property of RTC Report?
  • Options
    BeliasBelias Member Posts: 2,998
    with an IIF(....) statement...but it's simpler if you just do it in nav: calculate it in a variable, and show the variable in the report
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    MclarenMclaren Member Posts: 47
    Ya. U R Correct. But I have to perform Two functions. One is to Print X and One is IF Y and Z = 0 I have to print X also as 0. Please Belias Provide me a solution.
  • Options
    BeliasBelias Member Posts: 2,998
    I already provided it: create "x" variable in nav, calculate it with the code i wrote above, put the variable in the right section in classic client, set the expression of a textbox in the rdlc as =Fields!x.Value

    I don't know how to explain you more than this :-k
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    MclarenMclaren Member Posts: 47
    Hi I have tried this Codes to assign a value to DecPrice Variable.but Its executing the Else Part only.
    XXXXX.GET;


    XXXXX.SETRANGE("Qty",XXXXX."Qty");
    DecCost := XXXXX."Cost" * XXXXX."YQuantity";
    IF (XXXXX."Qty" <> 0) THEN
    DecPrice :=(DecCost/(XXXXX."Qty"))

    ELSE
    DecPrice := 1;


    Can Some one provide me a solution on this. Any Help will be appreciated.
  • Options
    matttraxmatttrax Member Posts: 2,309
    Mclaren wrote:
    but Its executing the Else Part only.

    So what does that tell you then? That the IF part of the statement is returning a FALSE, or XXXX.Qty is equal to zero. It's easy to check with the debugger.
  • Options
    jmagnojmagno Member Posts: 15
    "XXXXX.SETRANGE("Qty",XXXXX."Qty");"

    May be you need to double check the syntax of your code...
  • Options
    SavatageSavatage Member Posts: 7,142
    perhaps qty is a flowfield? then you need to use calcfields, it's hard to tell with the information given.

    also XXXXX.GET;

    isn't getting anything unless it's some setup table
    http://msdn.microsoft.com/en-us/library/dd338616.aspx
Sign In or Register to comment.