Any ratio function with X on the bottom has a chance of the denominator being zero, which is a program ending event without error handling. When Y = K/X where X is approaching zero then Y is approaching infinity, either negatively or positively. Its a vertical asymptote. The best solution would be to just not draw that interior line that crosses the asymptote, in effect imagine arrowheads on the ends of the lines drawn pointing to infinity. The second best solution and a much easier one is to capture the error and set the value of Y to zero when the denominator is zero. With the imprecision of doubles variables this happens less than it should theoretically. Nevertheless we have to set an error trap for divide by zero and have a plan when it happens. Setting the value of Y to zero is a good compromise. The lines that are heading to infinity are stopped and the line that *approximates* the asymptote is drawn. For accuracy, the line should then be erased.

The equation functions return a single value for Y and are a natural place for the error handler. It’s only required on the functions with an X value in the denominator.

Function C_06(X As Double) As Double
On Error GoTo HandlError
C_06 = (A * (X ^ 2) + B * X + C) / (D * (X ^ 2) + E * X + F)
ExitHere:
Exit Function
HandlError:
If Err.Number = 11 Then
MsgBox "div by zero"
C_06 = 0
End If
End Function

### Like this:

Like Loading...

*Related*