Divides the numerator by denominator, preventing a division by zero error.
Function SafeDivide(Numerator As Number, Denominator As Number) As Number
If Denominator<>0 Then SafeDivide=Numerator\Denominator
End Function
Parameters
- numerator
- The upper portion of the fraction.
- denominator
- The lower portion of the fraction.
Return Value
A numeric value or null.
Remarks
none
Example
SafeDivide({table.field0},{table.field1})
Requirements
This function requires the use of Basic Syntax.
Was just looking for something else and i came across this. This will fail under certain conditions. To get it to work right do the following:
Function SafeDivide(Numerator As Number, Denominator As Number) As Number
If Denominator0 Then
if Numerator0 then
SafeDivide=Numerator\Denominator
end if
end if
End Function
OR (.NET only)
Function SafeDivide(Numerator As Number, Denominator As Number) As Number
If Denominator0 AndAlso Numerator0 Then
SafeDivide=Numerator\Denominator
end if
End Function
Pingback: Cogniza: Extreme Insight » Blog Archive » Crystal Reports: Strategy to Localize a Report (labels)