Solved

VB.net form for converting DMS to Decimal Degrees

Posted on 2013-05-21
5
595 Views
Last Modified: 2013-05-22
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

0
Comment
Question by:Nate_LR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
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

by:Arthur_Wood
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

by:
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

by:Nate_LR
ID: 39188342
Thanks
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 39188354
Glad to be of assistance.

AW
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question