Results 1 to 7 of 7

Thread: Converting decimal degrees to degrees minutes seconds.

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    3

    Converting decimal degrees to degrees minutes seconds.

    Hey there,

    I've got an issue converting degrees to DMS.

    The whole units of degrees will remain the same (i.e. in 121.135°, start with 121°).
    Multiply the decimal by 60 (i.e. .135 * 60 = 8.1).
    The whole number becomes the minutes (8').
    Take the remaining decimal and multiply by 60. (i.e. .1 * 60 = 6).
    The resulting number becomes the seconds (6"). Seconds can remain as a decimal.

    I was curious how i could take only the whole digits out of each number (i.e. 8' and 6") and apply them to a variable then continue on with the calc.

    Any help would be much appreciated.

    Thanks

  2. #2
    Hyperactive Member Max Peck's Avatar
    Join Date
    Oct 2007
    Posts
    384

    Re: Converting decimal degrees to degrees minutes seconds.

    Simple. Create a form (I'm using VB.Net here) with a TextBox and a command button. Here's the code under the command button.

    vb Code:
    1. Private Sub btnToDMS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToDMS.Click
    2.  
    3.     Dim H, M, S As Integer
    4.     Dim XReg As Double
    5.  
    6.     XReg = Val(txtDisplay.Text)
    7.     H = Int(XReg)
    8.     XReg -= H
    9.     XReg *= 60
    10.     M = Int(XReg)
    11.     XReg -= M
    12.     XReg *= 60
    13.     S = Int(XReg)
    14.  
    15.     txtDisplay.Text = H & "." & Format(M, "00") & "." & Format(S, "00")
    16.  
    17. End Sub

    Yeah, I know I'm using some pre Dot-Net constructs in the code; but they're still usable. If you really want to use TryParse instead of Val go ahead - but this will work. Put 121.135 in the text box, click the button and you'll get 121.08.06. Format it as you like.

    HTH,

    -Max
    Last edited by Max Peck; Aug 31st, 2009 at 10:48 AM.
    The name's "Peck" .... "Max Peck"

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    3

    Re: Converting decimal degrees to degrees minutes seconds.

    Thanks a bunch, that looks good.

    But the thing is, this is going into a function for excell. can i get rid of the button command? (as you can tell im extremely new to this)

    Thanks in advance

  4. #4
    Hyperactive Member Max Peck's Avatar
    Join Date
    Oct 2007
    Posts
    384

    Post Re: Converting decimal degrees to degrees minutes seconds.

    Quote Originally Posted by k0ve View Post
    Thanks a bunch, that looks good.

    But the thing is, this is going into a function for excell. can i get rid of the button command? (as you can tell im extremely new to this)

    Thanks in advance
    Sure you can. I just put it into a button event for testing purposes. You might want to code it as a function instead - like this:

    vb Code:
    1. Private Function DDDtoDMS(ByVal text As String) As String
    2.  
    3.         Dim H, M, S As Integer
    4.         Dim XReg As Double
    5.  
    6.         XReg = Val(text)
    7.         H = Int(XReg)
    8.         XReg -= H
    9.         XReg *= 60
    10.         M = Int(XReg)
    11.         XReg -= M
    12.         XReg *= 60
    13.         S = Int(XReg)
    14.  
    15.         Return (H & "." & Format(M, "00") & "." & Format(S, "00"))
    16.  
    17.     End Function

    Then you just would just pass the string to it and it would be returned as a string. Here's how I called it from the button control:

    vb Code:
    1. Private Sub btnToDMS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToDMS.Click
    2.  
    3.         txtDisplay.Text = DDDtoDMS(txtDisplay.Text)
    4.  
    5.     End Sub

    -Max
    The name's "Peck" .... "Max Peck"

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    3

    Re: Converting decimal degrees to degrees minutes seconds.

    Thanks loads dude, i'l see how that works for me.

    cheers

  6. #6
    Junior Member
    Join Date
    Aug 2009
    Posts
    28

    Re: Converting decimal degrees to degrees minutes seconds.

    Hi there!!

    I try this code, its works!!..may i know it is decimal degrees same as radiant?

  7. #7
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Converting decimal degrees to degrees minutes seconds.

    That's a NO!

    In Radians a full circle is 2*PI, in degrees a circle is 360 degrees.

    With all your math knowledge you should be able to convert in all directions !-)
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

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