locked
divide by Zero error RRS feed

  • Question

  • I get a divide by zero error dialog that crashes SB7, here is part of the code that causes the crash.

        'Base Selling Price
        ItemBSP = ItemNUC/ItemCM
        ItemBPS = (0.01*Math.Floor(ItemBSP *100))
        GraphicsWindow.BrushColor = "#EEE8AA"
        GraphicsWindow.FillRectangle (136,466,88,18)'(135,465,90,20)
        GraphicsWindow.brushColor = "black"
        GraphicsWindow.DrawText (140,468,ItemBSP)

    This happens when ItemNUC or ItemCM is 0 because the data for these variables has not been entered yet when the program reads this line.

    I worked around it with the following;
        If ItemCM > 0 then  'Will not calculate if ItemCM is zero
        BSPcalc ()
        endif

    Sub BSPcalc
      ItemBSP = ItemNUC/ItemCM
      EndSub

    Is dividing by zero a bug? or just not good practice?
    Thanks,
    Steve
    Tuesday, March 2, 2010 11:15 PM

Answers

  • Thanks Hacker2,
    Makes since, I guess that I expected SB to ignore it or handle it some other way than to crash.
    • Marked as answer by SFC-P33A Wednesday, March 3, 2010 1:42 AM
    Wednesday, March 3, 2010 1:42 AM

All replies

  • No it is bot a bug, it is just mathmatically impossible to  divide by Zero.
    Wednesday, March 3, 2010 1:20 AM
  • Thanks Hacker2,
    Makes since, I guess that I expected SB to ignore it or handle it some other way than to crash.
    • Marked as answer by SFC-P33A Wednesday, March 3, 2010 1:42 AM
    Wednesday, March 3, 2010 1:42 AM