fishcakes said:
i am trying to calculate the arccosine of a number and keep getting an error
message:
undefined function in "ACOS" expression. I am following the syntax in the
help menu and my number is between -1 and 1 as specified.
Any suggestions?
Public Function ACos(dblX As Double, strUnit As String) As Double
'strUnit = "Degree" for degrees and "Radian" for radians
Const Pi = 3.14159265358979
Dim dblThetaRad As Double
If dblX > 1 Or dblX < -1 Then
MsgBox ("Input outside of range for ACos function.")
ACos = 0
Exit Function
End If
If dblX = 1 Then
ACos = 0
Exit Function
End If
If dblX = -1 Then
If strUnit = "Degree" Then
ACos = 180
Else
ACos = Pi
End If
Exit Function
End If
'Microsoft's version from A97 help - Derived Math Functions
dblThetaRad = Atn(-dblX / Sqr(-dblX * dblX + 1)) + 2 * Atn(1)
'My version
dblThetaRad = Pi / 2 - Sgn(dblX) * Atn(Abs(dblX) / Sqr(1 - dblX ^ 2))
If strUnit = "Degree" Then
ACos = dblThetaRad * 180# / Pi
Else
ACos = dblThetaRad
End If
End Function
James A. Fortune