Divison By zero error

ayamas
ayamas Member Posts: 15
Hi guys,
I have a problem.I am new to navision development.I hv designed a report.When I run that report on the 107th page I get a error Division by zero.I dont think its practical to debug it.
Can anyone please tell me how can i handle the error & whats the exact syntax to do it.
Thanks in advance.

Comments

  • jhoek
    jhoek Member Posts: 216
    Why wouldn't it be practical to debug? Debugger active, but Breakpoint on Triggers off?

    Handling the error, I'm afraid, involves not dividing by zero! :wink:
    Kind regards,

    Jan Hoek
    Product Developer
    Mprise Products B.V.
  • ayamas
    ayamas Member Posts: 15
    No the problem is in my report I am displaying the GP(%) of an item.But there are some items whose purchase price is zero I mean suppliers give it for free for ex (on 10 pieces 1 piece free) at tat time I get this error.
  • jhoek
    jhoek Member Posts: 216
    If your problem is that the division was entered as the SourceExpr of a report control, consider replacing the SourceExpr with a call to a function that returns the GP% both in normal (purchase price <> 0) and exceptional cases (purchase price = 0).
    Kind regards,

    Jan Hoek
    Product Developer
    Mprise Products B.V.
  • DenSter
    DenSter Member Posts: 8,307
    so make it that you never divide by zero, that's not a difficult thing to do.
    IF y = 0 THEN y := 1;
    SomeValue := x/y;
    
    or
    IF y = 0 THEN
      ErrorMsg := 'GP is zero'
    ELSE
      SomeValue := x/y;
    
    something like that. Be creative :)
  • OscarA
    OscarA Member Posts: 11
    I'm having the same problem ( the division by zero error ).
    In some languages there's an infinitesimal value that we can use to solve those kinds of problems, i.e.:

    instead of:
    y=x/z

    we use:

    y=x/(z+min)

    min is the infinitesimal value.

    Does navision has a function/constant anything that returns the minimum value that the system accepts?
  • ara3n
    ara3n Member Posts: 9,258
    nope. And I wouldn't use this solution in navision.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • OscarA
    OscarA Member Posts: 11
    ara3n wrote:
    nope. And I wouldn't use this solution in navision.

    why?
  • ara3n
    ara3n Member Posts: 9,258
    if z = 0 is works fine.


    What I mean is, the developer will should catch the division by zero.
    if they are missing it now in their code, they will still miss adding (min) in their code.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • muksha
    muksha Member Posts: 274
    Yes, ara3n is right, we should maintain the standards of navision. Problem of division by zero may be avoiding by storing the value in a variable and run the output where is not equal to zero. This is the best way to deal with this error.
    Mukesh Sharma
  • ara3n
    ara3n Member Posts: 9,258
    Muksha
    It appears you agree with me a lot. :D

    http://www.mibuso.com/forum/viewtopic.php?t=11694&highlight=
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Miklos_Hollender
    Miklos_Hollender Member Posts: 1,629
    The interesting thing is that if you ask a mathematician, he will say division by zero is a wrong operation, it should not yield a value but if you ask an accountant, he will say it should return 0.

    If you don't have any sales, sales price etc. then the profit is obviously 0 - so code it this way.