I have the following functions:
[code=vb]
Option Compare Database
Option Explicit
Public Function CalculateDistan ce(Lat1, Lon1, Lat2, Lon2) As Double
Dim a, b, c, x As Double
Const PI = 3.1415926535897 9
Const RadiusEarth = 3958.75587
Const MtNM = 0.868976242
' 1 Degree is 69.096 miles, 1 mile is 1609.34 m
a = Cos(Lat1 * PI / 180) * Cos(Lat2 * PI / 180) * Cos(Lon1 * PI / 180) * Cos(Lon2 * PI / 180)
b = Cos(Lat1 * PI / 180) * Sin(Lon1 * PI / 180) * Cos(Lat2 * PI / 180) * Sin(Lon2 * PI / 180)
c = Sin(Lat1 * PI / 180) * Sin(Lat2 * PI / 180)
x = a + b + c
If x >= 1 Or x <= -1 Then
CalculateDistan ce = 0
Else
CalculateDistan ce = Acos(x) * RadiusEarth * MtNM
End If
End Function
Public Function Acos(x)
Acos = Atn(-x / Sqr(-x * x + 1)) + PI / 2
End Function
[/code]
When I try to run, it's coming up as undefined. This was orginally an Excel function, slightly modified to work in Access. I can't figure out what's wrong with it. Anyone see the error?
[code=vb]
Option Compare Database
Option Explicit
Public Function CalculateDistan ce(Lat1, Lon1, Lat2, Lon2) As Double
Dim a, b, c, x As Double
Const PI = 3.1415926535897 9
Const RadiusEarth = 3958.75587
Const MtNM = 0.868976242
' 1 Degree is 69.096 miles, 1 mile is 1609.34 m
a = Cos(Lat1 * PI / 180) * Cos(Lat2 * PI / 180) * Cos(Lon1 * PI / 180) * Cos(Lon2 * PI / 180)
b = Cos(Lat1 * PI / 180) * Sin(Lon1 * PI / 180) * Cos(Lat2 * PI / 180) * Sin(Lon2 * PI / 180)
c = Sin(Lat1 * PI / 180) * Sin(Lat2 * PI / 180)
x = a + b + c
If x >= 1 Or x <= -1 Then
CalculateDistan ce = 0
Else
CalculateDistan ce = Acos(x) * RadiusEarth * MtNM
End If
End Function
Public Function Acos(x)
Acos = Atn(-x / Sqr(-x * x + 1)) + PI / 2
End Function
[/code]
When I try to run, it's coming up as undefined. This was orginally an Excel function, slightly modified to work in Access. I can't figure out what's wrong with it. Anyone see the error?
Comment