S
Squinado
Hi
I'm a VB beginner using MS Access 2002
I'm trying to use the Haversine formula to calculate distances between
geographic locations (lat longs) contained in a database. I have written a
module to do this - the module contains trig and compiles OK. When I try to
use this module in a query I get an 'undefined function in expression' error.
Any suggestions would be appreciated.
My Haversine module;
Option Explicit
Const r As Integer = 6367
Dim lat1 As Double
Dim lat2 As Double
Dim lon1 As Double
Dim lon2 As Double
Dim dlat As Double
Dim dlon As Double
Dim A As Double
Dim C As Double
Dim d As Double
Public Function Haversine(lat1, lon1, lat2, lon2) As Double
dlat = lat2 - lat1
dlon = lon2 - lon1
A = ((Sin(dlat / 2)) * (Sin(dlat / 2))) + Cos(lat1) * Cos(lat2) * ((Sin(dlon
/ 2)) * (Sin(dlon / 2)))
C = 2 * Atn(A / Sqr(-A * A + 1))
d = r * C
Haversine = d
End Function
I'm a VB beginner using MS Access 2002
I'm trying to use the Haversine formula to calculate distances between
geographic locations (lat longs) contained in a database. I have written a
module to do this - the module contains trig and compiles OK. When I try to
use this module in a query I get an 'undefined function in expression' error.
Any suggestions would be appreciated.
My Haversine module;
Option Explicit
Const r As Integer = 6367
Dim lat1 As Double
Dim lat2 As Double
Dim lon1 As Double
Dim lon2 As Double
Dim dlat As Double
Dim dlon As Double
Dim A As Double
Dim C As Double
Dim d As Double
Public Function Haversine(lat1, lon1, lat2, lon2) As Double
dlat = lat2 - lat1
dlon = lon2 - lon1
A = ((Sin(dlat / 2)) * (Sin(dlat / 2))) + Cos(lat1) * Cos(lat2) * ((Sin(dlon
/ 2)) * (Sin(dlon / 2)))
C = 2 * Atn(A / Sqr(-A * A + 1))
d = r * C
Haversine = d
End Function