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.
No tags

chuck arinze · May 14, 2007 at 9:33 am
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
Cogniza: Extreme Insight » Blog Archive » Crystal Reports: Strategy to Localize a Report (labels) · July 9, 2009 at 10:09 am
[...] this keyword can only be used in formulae that are executed during the report’s Second Pass. The following Record Selection Formula, for example, will generate an [...]