My function works except when either of two arguments, Frac_5_PARtbl or Frac_5, pass null values. If the nulls are changed to zeroes, the function works, so I've tried using the Nz() function to change the nulls to zero, but without success. The error in the immediate window is "compile error: expected: expression." Making the arguments optional didn't work, either.
Am I doing something wrong?
Here's the code:
Am I doing something wrong?
Here's the code:
Code:
Option Compare Database
Option Explicit
Public Function FigFract5(Distance_Feet As Single, Frac_5 As Variant, Frac_5_PARtbl As Variant) As Variant
Dim FigFract0 As Variant
Dim Frac_Distance As Single
Dim FracPar As Variant
Dim Frac As Variant
Frac = Nz(Frac_5, 0)
FracPar = Nz(Frac_5_PARtbl, 0)
FigFract0 = 95
If Frac > 0 Then
If Distance_Feet > 6600 Or Distance_Feet < 8580 Then
Frac_Distance = 6600
ElseIf Distance_Feet = 8580 Or Distance_Feet = 9240 Then
Frac_Distance = 7920
ElseIf Distance_Feet > 9240 Or Distance_Feet < 10770 Then
Frac_Distance = 9240
ElseIf Distance_Feet > 10560 Or Distance_Feet < 11880 Then
Frac_Distance = 10560
ElseIf Distance_Feet = 11880 Then
Frac_Distance = 11220
End If
If Frac = FracPar And Frac > 0 Then
FigFract0 = 95
ElseIf FracPar > Frac Then
While FracPar >= Frac
FracPar = FracPar - 0.01
FigFract0 = (1 / FracPar * Frac_Distance / Distance_Feet) * 10 / 3 + FigFract0
Wend
ElseIf FracPar < Frac Then
While FracPar <= Frac
FracPar = FracPar + 0.01
FigFract0 = FigFract0 - (1 / FracPar * Frac_Distance / Distance_Feet) * 10 / 3
Wend
End If
FigFract5 = Round(FigFract0, 1)
ElseIf Frac = 0 Then FigFract5 = 0
End If
End Function