Solved

VB.net form for converting DMS to Decimal Degrees

Posted on 2013-05-21
5
584 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net creating Contact in Outlook 1 99
Data organization issue 7 56
Asp.Net Session Question 2 49
Help with modifying xml file using VB.NET 5 13
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 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