Link to home
Start Free TrialLog in
Avatar of Nate_LR
Nate_LR

asked on

VB.net form for converting DMS to Decimal Degrees

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

Open in new window

Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

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
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
ASKER CERTIFIED SOLUTION
Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nate_LR
Nate_LR

ASKER

Thanks
Glad to be of assistance.

AW