|
-
Aug 30th, 2009, 10:39 PM
#1
Thread Starter
New Member
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
-
Aug 31st, 2009, 10:44 AM
#2
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:
Private Sub btnToDMS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToDMS.Click Dim H, M, S As Integer Dim XReg As Double XReg = Val(txtDisplay.Text) H = Int(XReg) XReg -= H XReg *= 60 M = Int(XReg) XReg -= M XReg *= 60 S = Int(XReg) txtDisplay.Text = H & "." & Format(M, "00") & "." & Format(S, "00") 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
-
Aug 31st, 2009, 06:34 PM
#3
Thread Starter
New Member
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
-
Aug 31st, 2009, 07:49 PM
#4
Re: Converting decimal degrees to degrees minutes seconds.
 Originally Posted by k0ve
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:
Private Function DDDtoDMS(ByVal text As String) As String
Dim H, M, S As Integer
Dim XReg As Double
XReg = Val(text)
H = Int(XReg)
XReg -= H
XReg *= 60
M = Int(XReg)
XReg -= M
XReg *= 60
S = Int(XReg)
Return (H & "." & Format(M, "00") & "." & Format(S, "00"))
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:
Private Sub btnToDMS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToDMS.Click
txtDisplay.Text = DDDtoDMS(txtDisplay.Text)
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
-
Aug 31st, 2009, 08:22 PM
#5
Thread Starter
New Member
Re: Converting decimal degrees to degrees minutes seconds.
Thanks loads dude, i'l see how that works for me.
cheers
-
Sep 2nd, 2009, 12:33 AM
#6
Junior Member
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?
-
Sep 2nd, 2009, 06:32 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|