Advertisement

07.15.2008 at 12:15PM PDT, ID: 23567258
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

I'm looking for the Haversine (LAT/LONG) formula in VBA...

Asked by nike_golf in Microsoft Excel Spreadsheet Software, Visual Basic Programming, Microsoft Visual Basic.Net

I'm trying to convert the Haversine formula from VB.NET to VBA but am running into some problems. Does anyone have this converted already?

Imports System.Text
Public Class CDistanceBetweenLocations
    Public Shared Function Calc(ByVal Lat1 As Double, ByVal Long1 As Double, ByVal Lat2 As Double, ByVal Long2 As Double) As Double
        '
        ' The Haversine formula according to Dr. Math.
        ' http://mathforum.org/library/drmath/view/51879.html
        '
        ' dlon = lon2 - lon1
        ' dlat = lat2 - lat1
        ' a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
        ' c = 2 * atan2(sqrt(a), sqrt(1-a))
        ' d = R * c
        '
        ' Where
        ' * dlon is the change in longitude
        ' * dlat is the change in latitude
        ' * c is the great circle distance in Radians.
        ' * R is the radius of a spherical Earth.
        ' * The locations of the two points in
        ' spherical coordinates (longitude and
        ' latitude) are lon1,lat1 and lon2, lat2.
        '

        Dim dDistance As Double = [Double].MinValue
        Dim dLat1InRad As Double = Lat1 * (Math.PI / 180)
        Dim dLong1InRad As Double = Long1 * (Math.PI / 180)
        Dim dLat2InRad As Double = Lat2 * (Math.PI / 180)
        Dim dLong2InRad As Double = Long2 * (Math.PI / 180)

        Dim dLongitude As Double = dLong2InRad - dLong1InRad
        Dim dLatitude As Double = dLat2InRad - dLat1InRad

        ' Intermediate result a.

        Dim a As Double = Math.Pow(Math.Sin(dLatitude / 2), 2) + Math.Cos(dLat1InRad) * Math.Cos(dLat2InRad) * Math.Pow(Math.Sin(dLongitude / 2), 2)

        ' Intermediate result c (great circle distance in Radians).

        Dim c As Double = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a))

        ' Distance.

        ' R (Earth Radius) mi = 3956.0, nm = 3437.7, 6367.0 = km, 6962560 = Yards, 20887680 = Feet ' comment

        'Const kEarthRadiusKms As Double = 6376.5
        Const kEarthRadiusKms As Double = 6962560
        dDistance = kEarthRadiusKms * c

        Return dDistance
    End Function
End ClassStart Free Trial
[+][-]07.15.2008 at 12:25PM PDT, ID: 22010144

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Excel Spreadsheet Software, Visual Basic Programming, Microsoft Visual Basic.Net
Sign Up Now!
Solution Provided By: zorvek
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.15.2008 at 12:26PM PDT, ID: 22010150

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.15.2008 at 12:30PM PDT, ID: 22010181

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.15.2008 at 12:56PM PDT, ID: 22010434

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628