Solved

# VB.net form for converting DMS to Decimal Degrees

Posted on 2013-05-21
547 Views
I'm trying to create a simple form to convert degrees minutes seconds to decimal degrees, but I'm having trouble when converting negative numbers.  When I try to convert -92 7 6.52 I get -91.8815222 but the answer should be -92.118478.  Why is this simple formula not working?
``````Private Sub btnDecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecimal.Click

'txtLatDecimal.Text = Math.Round(CInt(txtLatDegrees.Text) + (CInt(txtLatMin.Text) / 60) + (CDec(txtLatSec.Text) / 3600), 7)

'txtLngDecimal.Text = Math.Round(CInt(txtLngDegrees.Text) + (CInt(txtLngMin.Text) / 60) + (CDec(txtLngSec.Text) / 3600), 7)

txtLatDecimal.Text = Math.Round(((CDec(txtLatSec.Text) / 60) + CInt(txtLatMin.Text)) / 60 + CInt(txtLatDegrees.Text), 7)
txtLngDecimal.Text = Math.Round(((CDec(txtLngSec.Text) / 60) + CInt(txtLngMin.Text)) / 60 + CInt(txtLngDegrees.Text), 7)

End Sub
``````
0
Question by:Nate_LR
• 3

LVL 23

Expert Comment

ID: 39185999
Hi,

You are adding positive numbers to negative, so the result is closer to zero:
6.52/60+7/60-92 results to -91.8815222.

Giannis
0

LVL 44

Expert Comment

ID: 39187105
You need to determine the sign of txtLngDegrees.Text and then apply that sign to the other parts of your formula. Thus your formula would become

-6.52/60 - 7/60 - 92 = -92.118478

AW
0

LVL 44

Accepted Solution

Arthur_Wood earned 500 total points
ID: 39187249
try this:

Dim signLng as Integer = CInt(txtLngDegrees.Text)/Abs(CInt(txtLngDegrees.Text))
Dim signLat  as Integer = CInt(txtLatDegrees.Text)/Abs(Cint(txtLatDegrees.Text))

txtLatDecimal.Text = Math.Round((( signLat*CDec(txtLatSec.Text) / 60) + signLat*CInt(txtLatMin.Text)) / 60 + CInt(txtLatDegrees.Text), 7)
txtLngDecimal.Text = Math.Round((signLng*(CDec(txtLngSec.Text) / 60) + signLng*CInt(txtLngMin.Text)) / 60 + CInt(txtLngDegrees.Text), 7)

AW
0

Author Closing Comment

ID: 39188342
Thanks
0

LVL 44

Expert Comment

ID: 39188354

AW
0

## Featured Post

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…