locked
Divide By Zero Error RRS feed

  • Question

  • Hi Guys,

    I have an equation used in SSRS but I got some divide by zero error. So, I tried the following options.

    =IIF(ReportItems!textbox38.Value<>0,(ReportItems!textbox38.Value/(iif(ReportItems!textbox38.Value=0, 1,ReportItems!textbox38.Value)+ReportItems!textbox39.Value)),0)

    But this one did not solve my problem then I copied the following syntax to the report code.

    Public Function Divide(ByVal first As Double, ByVal second As Double) As Double
            If second = 0 Then
                Return 0
            Else
                Return first / (first+second)
            End If
        End Function

    However, when I am giving this Code.Divide(ReportItems!textbox38.Value) value it is giving unknown member error at Divide.

    Friday, March 11, 2011 4:45 PM

Answers

  • I guess Tab Alleman 2 made a strong point. Please try modifying your function as given below. Note the first line is modified to have (first+second) in place of only second. Yet you need to pass the both the parameters for the function to work properly. =Code.Divide(ReportItems!textbox38.Value,ReportItems!textbox39.Value)

    Public Function Divide(ByVal first As Double, ByVal second As Double) As Double
      If (first+second) = 0 Then
       Return 0
      Else
       Return first / (first+second)
      End If
    End Function
    

    Hope this helps


    Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful.

    BH

    • Marked as answer by Challen Fu Sunday, March 20, 2011 2:05 PM
    Tuesday, March 15, 2011 3:49 AM

All replies

  • You have two parameters in your function (first and second). But the call to the function Code.Divide(ReportItems!textbox38.value) passes only one parameter. You need to pass both parameters as the sample shown below

    Code.Divide(ReportItems!textbox38.Value,ReportItems!textbox39.Value)

    Hope this helps. Please feel free to discuss if you have any further questions.

     


    Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful.

    BH

    Saturday, March 12, 2011 7:47 AM
  • Hi,

    you can use iif condition to resolve this in the expression

    e.g

    iff(fields!denominator.value=0,null,fields!denominator.value)

    please mark as answer if this post helps..

    Thanks,

    Shobhit

    Sunday, March 13, 2011 6:58 AM
  • Hi Shobit,

    I tried this option but could not resolve this problem. Any more Suggestions?

    Thanks for the response.

    Tarak

    Monday, March 14, 2011 3:18 PM
  • if you are adding the two values as the denominator, why are you only checking to see if one of them is zero?   What if one of them is 1, and the other is -1?

    Instead why not test if first + second = 0?


    -Tab Alleman
    Monday, March 14, 2011 4:03 PM
  • I guess Tab Alleman 2 made a strong point. Please try modifying your function as given below. Note the first line is modified to have (first+second) in place of only second. Yet you need to pass the both the parameters for the function to work properly. =Code.Divide(ReportItems!textbox38.Value,ReportItems!textbox39.Value)

    Public Function Divide(ByVal first As Double, ByVal second As Double) As Double
      If (first+second) = 0 Then
       Return 0
      Else
       Return first / (first+second)
      End If
    End Function
    

    Hope this helps


    Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful.

    BH

    • Marked as answer by Challen Fu Sunday, March 20, 2011 2:05 PM
    Tuesday, March 15, 2011 3:49 AM