Dividing by Zero in ProLaw Reports
It may be necessary to use Visual Basic code in your reports. This can accomplish a number of tasks that the default report functionality may not be able to accomplish. This document does not attempt to teach you how to write VB code. Just to give you a very common example of when this is to be used. Our scenario will go over division. The author of this document uses this method instead of the default way of doing division: Field / Field. When using a formula like that for division, SSRS may error when dividing by 0. As such, we will want to use this VB code. To use this please go to report properties by right clicking on the background of the report, not the body, report properties, code. Paste this into the bottom of that window.
Public Shared Function DividebyZero(ByVal Actual As Decimal, ByVal Total As Decimal) As Decimal
If Total = 0 Then
Return 0
End If
Return (Actual / Total)
End Function
After that function has been added, we will write our expression like this.
=Code.DividebyZero(Fields!FirstField.Value, Fields!LYTDBalance.Value)
ProLaw Report Building Tips
#ProLaw #ProLawReports #Divide