Zum Hauptinhalt gehen

VBScript to convert DD to DMS

Kommentare

2 Kommentare

  • Permanently deleted user

    I think I've got it after lots of trial and error. Hopefully this helps someone else. It was a combination of not understanding the activity, like I said, and some syntax.

    I was missing an ampersand, trying to call a function within a function, and not calling the math functions properly. Here is the finished script that goes inside the VBScript text box:

    Dim degrees

     

    Dim deg

     

    Dim minutes

     

    Dim seconds

     

    Dim min

     

    Dim minInt

     

    Dim sec

     

    Dim secRound

     

    Dim west

     

    If myCoord < 0 then

     

    degrees = Math.Abs(myCoord)

     

    west = True

     

    Else

     

    degrees = myCoord

     

    west = False

     

    End if

     

    deg = Math.Floor(degrees)

     

    minutes = degrees - deg

     

    min = minutes * 60

     

    minInt = Math.Floor(min)

     

    seconds = min - minint

     

    sec = seconds * 60

     

    secRound = Math.Round(sec,6)

     

    If west = True Then

     

    myDMS = deg & " d " & minInt & " m " & secRound & " W"

     

    Else

     

    myDMS = deg & " d " & minInt & " m " & secRound & " N"

     

    End if

     

    Return myDMS

    Parameters:

    Name=myCoord, Direction= In/Out, Type=Double, Assign To dblX

     

    Name=myDMS, Direction= In/Out, Type=String, Assign To xCoordDMS
    0
  • Richard Diaz

    Heather,

    Thanks for the code.  I tried this but found that results took about 30 seconds to return the answer.  I replaced your vb code with the following that I found on the internet and the results return much quicker.

    Dim DecDegAbs As Decimal = Math.Abs(myCoord)

     

    Dim ReturnValue As String = "'"

     

    Dim DegreeSymbol As String = "°"

     

    Dim MinutesSymbol As String = "’"

     

    Dim SecondsSymbol As String = """"

     

    Dim Degrees As String = Math.Truncate(DecDegAbs) & DegreeSymbol

     

    Dim MinutesDecimal As Decimal = (DecDegAbs - Math.Truncate(DecDegAbs)) * 60

     

    Dim SecondsDecimal As Decimal = (MinutesDecimal - Math.Truncate(MinutesDecimal))

     

    Dim Minutes As String = Math.Truncate(MinutesDecimal) & MinutesSymbol

     

    Dim Seconds As String = String.Format("{0:##.0000}", (SecondsDecimal * 60)) & SecondsSymbol

     

    myDMS = Degrees & " " & Minutes & " " & Seconds

     

    Return myDMS

     

    Best Regards,

    Rick

     

    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.