Paste the functions below into a module (click New on the Modules tab of
Database Window). You can then use them like the built-in functions.
(These come from an old sample database Microsoft released years ago, named
neatcode.mdb.)
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Nigel said:
I was wondering if there is an equivalant function to ACOS in Access, the
function is available in VBA for Excel but I cannot find it in Access, I
know
it has COS, Tan and Sin but I really need th ACOS function
Function ArcCos(X As Double) As Double
' Inverse Cosine
If X = 1 Then
ArcCos = 0
ElseIf X = -1 Then
ArcCos = -PI()
Else
ArcCos = Atn(X / Sqr(-X * X + 1)) + PI() / 2
End If
End Function
Function Arccosec(X As Double) As Double
' Inverse Cosecant
Arccosec = Atn(X / Sqr(X * X - 1)) + (Sgn(X) - 1) * PI() / 2
End Function
Function Arccotan(X As Double) As Double
' Inverse Cotangent
Arccotan = Atn(X) + PI() / 2
End Function
Function ArcSec(X As Double) As Double
' Inverse Secant
ArcSec = Atn(X / Sqr(X * X - 1)) + Sgn(Sgn(X) - 1) * PI() / 2
End Function
Function ArcSin(X As Double) As Double
' Inverse Sine
If X = 1 Then
ArcSin = PI() / 2
ElseIf X = -1 Then
ArcSin = -PI() / 2
Else
ArcSin = Atn(X / Sqr(-X * X + 1))
End If
End Function
Function ATan2(X As Double, Y As Double) As Double
'
' Returns the ArcTangent based on X and Y coordinates
' If both X and Y are zero an error will occur.
'
' The positive X axis is assumed to be 0, going poistive in the
' counterclockwise direction, and negative in the clockwise direction.
'
If X = 0 Then
If Y = 0 Then
ATan2 = 1 / 0
ElseIf Y > 0 Then
ATan2 = PI() / 2
Else
ATan2 = -PI() / 2
End If
ElseIf X > 0 Then
If Y = 0 Then
ATan2 = 0
Else
ATan2 = Atn(Y / X)
End If
Else
If Y = 0 Then
ATan2 = PI()
Else
ATan2 = (PI() - Atn(Abs(Y) / Abs(X))) * Sgn(Y)
End If
End If
End Function
Function Cosec(X As Double) As Double
' Cosecant
Cosec = 1 / Sin(X)
End Function
Function Cotan(X As Double) As Double
' Cotangent
Cotan = 1 / Tan(X)
End Function
Function Deg2Rad(X As Double) As Double
' Degrees to radians
Deg2Rad = X / 180 * PI()
End Function
Function HArccos(X As Double) As Double
' Inverse Hyperbolic Cosine
HArccos = Log(X + Sqr(X * X - 1))
End Function
Function HArccosec(X As Double) As Double
' Inverse Hyperbolic Cosecant
HArccosec = Log((Sgn(X) * Sqr(X * X + 1) + 1) / X)
End Function
Function HArccotan(X As Double) As Double
' Inverse Hyperbolic Tangent
HArccotan = Log((X + 1) / (X - 1)) / 2
End Function
Function HArcsec(X As Double) As Double
' Inverse Hyperbolic Secant
HArcsec = Log((Sqr(-X * X + 1) + 1) / X)
End Function
Function HArcsin(X As Double) As Double
' Inverse Hyperbolic Sine
HArcsin = Log(X + Sqr(X * X + 1))
End Function
Function HArctan(X As Double) As Double
' Inverse Hyperbolic Tangent
HArctan = Log((1 + X) / (1 - X)) / 2
End Function
Function HCos(X As Double) As Double
' Hyperbolic Cosine
HCos = (Exp(X) + Exp(-X)) / 2
End Function
Function HCosec(X As Double) As Double
' Hyperbolic Cosecant = 1/HSin(X)
HCosec = 2 / (Exp(X) - Exp(-X))
End Function
Function HCotan(X As Double) As Double
' Hyperbolic Cotangent = 1/HTan(X)
HCotan = (Exp(X) + Exp(-X)) / (Exp(X) - Exp(-X))
End Function
Function HSec(X As Double) As Double
' Hyperbolic Secant = 1/HCos(X)
HSec = 2 / (Exp(X) + Exp(-X))
End Function
Function HSin(X As Double) As Double
' Hyperbolic Sine
HSin = (Exp(X) - Exp(-X)) / 2
End Function
Function HTan(X As Double) As Double
' Hyperbolic Tangent = HSin(X)/HCos(X)
HTan = (Exp(X) - Exp(-X)) / (Exp(X) + Exp(-X))
End Function
Function PI() As Double
PI = Atn(1) * 4
End Function
Function Rad2Deg(X As Double) As Double
' Radians to Degrees
Rad2Deg = X / PI() * 180
End Function
Function Sec(X As Double) As Double
' Secant
' This will choke at PI/2 and 3PI/2 radians (90 & 270 degrees)
'
Sec = 1# / Cos(X)
End Function