Version: Visual Studio 2012
Problem: I want to insert the following VBA code into Visual Studio and don't know how to do it. Also I don't know if I should insert this at the Application or Project Level. I need this code to streamline the "Divide by Zero" error when working in SSRS projects. I looked on-line and it was mentioned that the Developer Ribbon was needed and to get the Developer Ribbon I would need to install Office Developer Tools for Visual Studio 2012. I'm new to Visual Studio, but have been programming in VBA for a long-time. Any advise would be greatly appreciated.
Divide by Zero Code:
In the Menu; go to Report > Report Properties > Code and paste the code bellow
Public Function Quotient(ByVal numerator As Decimal, denominator As Decimal) As Decimal
If denominator = 0 Then
Return 0
Else
Return numerator / denominator
End If
End Function
To call the function go to the the Textbox expression and type:
=Code.Quotient(SUM(fields!FieldName.Value),SUM(Fields!FieldName2.Value))
in this case I am putting the formula at the Group level so I am using sum. Otherwise it would be:
=Code.Quotient(fields!FieldName.Value,Fields!FieldName2.Value)
From <http://williameduardo.com/development/ssrs/ssrs-divide-by-zero-error/>
Bob Sutor