Solved

VB.net form for converting DMS to Decimal Degrees

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now