Total Visual SourceBook

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office 2007 and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!

Separate version for Access/Office 2003, 2002, and 2000.

Separate version for:
Access 97/95


View all FMS products for Microsoft AccessAll Our Microsoft Access Products

SourceBook Info:

Why SourceBook?

 

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

 

 

 

Microsoft Access, Office/VBA, VB6 Modules royalty-free source code libraryMicrosoft Access Modules royalty-free source code libraryMicrosoft Access VBA and VB6 Module Library Free trial of Total Visual SourceBook for Microsoft Access, Office, VB6 and VBA

Module: Distance in Category Geospatial Mapping : Addresses and Distances from Total Visual SourceBook

Measure the distance between two latitude and longitude coordinates using the spherical law of cosines or Haversine formula in VBA or VB6.

Due to the curvature of the earth, the distance between two points is not a straight line. These routines calculate the distance over the earth as a sphere.

Procedure List

Procedure Name

Type

Description

(Declarations) Declarations Declarations and private variables for the modDistance module
DistanceCosines Procedure Calculate the arc distance between two latitude/longitude points based on the spherical law of cosines. In spherical trigonometry, the law of cosines (also called the cosine rule for sides) is a theorem relating the sides and angles of spherical triangles, analogous to the ordinary law of cosines from plane trigonometry. Reference: http://en.wikipedia.org/wiki/Spherical_law_of_cosines
DistanceHaversine Procedure Calculate the distance between two latitude/longitude points based on the Haversine formula. The Haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes. It is a special case of a more general formula in spherical trigonometry, the Law of Haversines, relating the sides and angles of spherical triangles. Reference: http://en.wikipedia.org/wiki/Haversine_formula
ArcCosine Procedure Get the arc cosine of the supplied radians
DegreesToRadians Procedure Convert degrees to radians (180 degrees equals PI radians)

Example Code for Using Module: Distance

' Example of modDistance
'
' To use this example, create a new module and paste this code into it.
' Then run the procedure by putting the cursor in the procedure and pressing:
'    F5 to run it, or
'    F8 to step through it line-by-line (see the Debug menu for more options)

Private Sub Example_modDistance()
  ' Comments: Examples of using the modDistance routines to measure the distance between two points in VBA and VB6.
  '           See the results in the Immediate Window.

  ' These are sample locations.
  ' To get values for a particular location, use the LatitudeLongitudeFromAddress function in the modGoogleMapsAPI module

  ' Location of the White House in Washington, DC
  Const cdblLatitude1 As Double = 38.8976831
  Const cdblLongitude1 As Double = -77.0364972

  ' Location of the Sydney Opera House, Australia
  Const cdblLatitude2 As Double = -33.857767
  Const cdblLongitude2 As Double = 151.2149929

  ' Location of Microsoft in Redmond, WA
  Const cdblLatitude3 As Double = 47.6447015
  Const cdblLongitude3 As Double = -122.1301371

  ' Location of the Forbidden City in Beijing, China
  Const cdblLatitude4 As Double = 39.91559
  Const cdblLongitude4 As Double = 116.396977

  ' Location of FMS offices at 8150 Leesburg Pike, Vienna, VA 22182, USA
  Const cdblLatitude5 As Double = 38.9165052
  Const cdblLongitude5 As Double = -77.2259664

  ' DistanceCosines: Calculate the arc distance between two latitude/longitude points based on the spherical law of cosines
  Debug.Print "Distance using the law of cosines between the White House and Syndey Opera House"
  Debug.Print DistanceCosines("M", cdblLatitude1, cdblLongitude1, cdblLatitude2, cdblLongitude2) & " miles"
  Debug.Print DistanceCosines("K", cdblLatitude1, cdblLongitude1, cdblLatitude2, cdblLongitude2) & " kilometers"
  Debug.Print DistanceCosines("N", cdblLatitude1, cdblLongitude1, cdblLatitude2, cdblLongitude2) & " nautical miles"
  Debug.Print

  ' DistanceHaversine: Calculate the distance between two latitude/longitude points based on the Haversine formula
  Debug.Print "Distance using the Haversine formula between the White House and Syndey Opera House"
  Debug.Print DistanceHaversine("M", cdblLatitude1, cdblLongitude1, cdblLatitude2, cdblLongitude2) & " miles"
  Debug.Print DistanceHaversine("K", cdblLatitude1, cdblLongitude1, cdblLatitude2, cdblLongitude2) & " kilometers"
  Debug.Print DistanceHaversine("N", cdblLatitude1, cdblLongitude1, cdblLatitude2, cdblLongitude2) & " nautical miles"
  Debug.Print

  ' DistanceCosines: Calculate the arc distance between two latitude/longitude points based on the spherical law of cosines
  Debug.Print "Distance using the law of cosines between FMS and the White House"
  Debug.Print DistanceCosines("M", cdblLatitude1, cdblLongitude1, cdblLatitude5, cdblLongitude5) & " miles"
  Debug.Print DistanceCosines("K", cdblLatitude1, cdblLongitude1, cdblLatitude5, cdblLongitude5) & " kilometers"
  Debug.Print DistanceCosines("N", cdblLatitude1, cdblLongitude1, cdblLatitude5, cdblLongitude5) & " nautical miles"
  Debug.Print

  ' DistanceHaversine: Calculate the distance between two latitude/longitude points based on the Haversine formula
  Debug.Print "Distance using the law of cosines between FMS and the White House"
  Debug.Print DistanceHaversine("M", cdblLatitude1, cdblLongitude1, cdblLatitude5, cdblLongitude5) & " miles"
  Debug.Print DistanceHaversine("K", cdblLatitude1, cdblLongitude1, cdblLatitude5, cdblLongitude5) & " kilometers"
  Debug.Print DistanceHaversine("N", cdblLatitude1, cdblLongitude1, cdblLatitude5, cdblLongitude5) & " nautical miles"

End Sub

Microsoft Access Module LibraryOverview of Total Visual SourceBook

The source code in Total Visual SourceBook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Additional Resources