Results 1 to 3 of 3

Thread: convert code from vb.net to vb6

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    convert code from vb.net to vb6

    can somebody help me to convert code below to become code used in vb6.

    Code:
    Public Function distance(ByVal lat1 As Double, ByVal lon1 As Double, ByVal lat2 As Double, ByVal lon2 As Double, ByVal unit As Char) As Double
        Dim theta As Double = lon1 - lon2
        Dim dist As Double = Math.Sin(deg2rad(lat1)) * Math.Sin(deg2rad(lat2)) + Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) * Math.Cos(deg2rad(theta))
        dist = Math.Acos(dist)
        dist = rad2deg(dist)
        dist = dist * 60 * 1.1515
        If unit = "K" Then
            dist = dist * 1.609344
        ElseIf unit = "N" Then
            dist = dist * 0.8684
        End If
        Return dist
    End Function
    
    Private Function deg2rad(ByVal deg As Double) As Double
        Return (deg * Math.PI / 180.0)
    End Function
    
    Private Function rad2deg(ByVal rad As Double) As Double
        Return rad / Math.PI * 180.0
    End Function

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: convert code from vb.net to vb6

    I think the only changes needed is how the functions return their values, and declaration of a value. Instead of Return use the function name, eg:
    Code:
    distance = dist
    ..and:
    Code:
    Dim theta As Double 
      theta = lon1 - lon2

  3. #3
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: convert code from vb.net to vb6

    Well, in VB 6, there isn't a Math class, so for the Sin & Cos, just use :
    Sin
    Cos
    without math. infront

    PI, I think you should still use the old fashioned way, and declare a Constant to PI
    Code:
     Const PI = 3.14159265358979
    VB.NET MVP 2008 - Present

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width