CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2008
    Posts
    7

    [RESOLVED] Help with a function please?

    Hi there,

    Can anyone help me please?

    I am developing a windows mobile application which talks to the GPS in the device to work out where some is.

    The code is based on some MS source code which i found on the net.

    But I have a problem with one of the functions. It seems to have a if statement which stops it working when the degrees is equal to zero, which it is in my part of the world. (UK)

    I cannot seem to get my head around how to change the function to make it work even if the degrees is zero.

    I have obviously tried taking out the "if" part but because the function includes dividing the result by the value of "degrees" it throws a divide by zero exception.

    Here is the function:

    /// <summary>
    /// Converts the decimal, minutes, seconds coordinate to
    /// decimal degrees
    /// </summary>
    /// <returns></returns>
    public double ToDecimalDegrees()
    {
    if (degrees == 0)
    return 0.0;

    int absDegrees = Math.Abs(degrees);

    double val = (double)absDegrees + ((double)minutes / 60.0) + ((double)seconds / 3600.0);

    return val * (absDegrees / degrees);
    }

    Can anyone help me please?

    Many thanks in advance

    Trev

  2. #2
    Join Date
    Aug 2008
    Posts
    7

    Resolved Re: Help with a function please?

    Please ignore this message I have now found the answer...

    http://social.msdn.microsoft.com/For...c-48a2ba36254c

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured