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
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:
..and:
Code:
Dim theta As Double
theta = lon1 - lon2
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