none
Devide By Zero

    Question

  • Hi

    Apologies if I'm in the wrong forum could not find SSRS

    I need help with to write a custom code in Visual Studio SSRS to have a 0 result when divided by zero instead of #Error calculations in a table

    Function what I have thus far: -

    Function DivZero(number as double) AS object

    If number = 0

    then DivZero = 1

    Else

    DivZero = number

    End If

    End Function

    Please correct the syntax as I get a syntax error and let me know how to use in an expression

    What I have is:

    =Sum(Code.DivZero(Fields!ATP.Value)) - (ATP is Amount/Trans Calculation)


    Thursday, April 07, 2016 1:08 PM

Answers

  • Thank you -- I struggle with using this in an expression as well

    I want to use it in a SUM expression

    Something like Code.DivZero(sum(ATP) ? or

    =Sum(Code.DivZero(Fields!ATP.Value)) ?

    But I get an error "Function divzero does not return a value on all code paths, a null reference exception could occur at run time when result is used"

    • Marked as answer by SSRS dummy Thursday, April 07, 2016 2:13 PM
    Thursday, April 07, 2016 2:13 PM

All replies

  • "then" belongs on the line with if number=0

        Function DivZero(number As Double) As Object
            If number = 0 Then
                DivZero = 1
            Else
                DivZero = number
            End If
        End Function
    

    Not sure what else you're having trouble with.  What's the error?

    Thursday, April 07, 2016 1:18 PM
  • Thank you -- I struggle with using this in an expression as well

    I want to use it in a SUM expression

    Something like Code.DivZero(sum(ATP) ? or

    =Sum(Code.DivZero(Fields!ATP.Value)) ?

    But I get an error "Function divzero does not return a value on all code paths, a null reference exception could occur at run time when result is used"

    • Marked as answer by SSRS dummy Thursday, April 07, 2016 2:13 PM
    Thursday, April 07, 2016 2:13 PM