Results 1 to 5 of 5

Thread: Degree minutes Second

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Degree minutes Second

    I have one textbox.

    I use the textbox to input the Value in Degree, Minutes, Second for example 60 Degree, 30 minutes, 30 seconds so I enter in the textbox like this 60.3030, How to Convert it into decimal degree?
    Last edited by matrik02; Feb 11th, 2012 at 07:52 AM.

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Degree minutes Second

    I able to use three textbox to convert degree, minutes and seconds into decimal degree. But I don't know how to use one textbox to 60.3030 to decimal degree

  3. #3
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: Degree minutes Second

    you need to parse the textbox into the three parts you need

    the text box is made up like so part1 point part2 part3

    you can get the value by an arithmetic or string manipulation


    please note the syntax for this may differ in your version of vb or other languages

    arithmetic:

    'get part 1
    degrees= int(val(text)) ' thats the integer value of the value of any leading numeric bits of the text

    'remove part1 from the text
    text=val(text)-degrees ' thats the whole number before the decimal point removed

    'get part 2
    minutes=int(val(text)*100) ' thats the whole number part of the remainder with the point moved 2 to the right

    'remove part 2
    text=val(text)*100 - minutes ' thats the whole number remover from text

    'get part 3
    seconds = val(text)*100 ' thats the point moved 2 to the right again

    all done!

    String method:

    get part 1

    degrees=left(text,instr(text,".")-1) ' from the left upto but not including the point

    remainder=mid(text,instr(text,".")+1) ' no length assumes whole of string returned

    minutes=left(remainder,2)

    seconds=right(remainder,2)

    all done

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Degree minutes Second

    Quote Originally Posted by matrik02 View Post
    I have one textbox.
    I use the textbox to input the Value in Degree, Minutes, Second for example 60 Degree, 30 minutes, 30 seconds so I enter in the textbox like this 60.3030, How to Convert it into decimal degree?
    The conversion to decimal is like this:
    Code:
    degrees + Minutes  / 60 + Seconds / 3600
    I do this conversion in some applications and i can tell you the best would be using 3 textboxes, not just one, this way it's easier for the user to input values and it's easier for you to work with them. Using 3 textboxes the code would be:
    Code:
    Round(CDBL(txtdeg.Text) + CDBL(txtmin.Text) / 60 + CDBL(txtsec.Text) / 3600, 3)
    EDIT: Sorry i didnt see your second post, the only difference I see when using 1 Textbox is that you need to use instr() and mid() to get degrees at left of the dot and then at right you have minutes and seconds, you can get these also using mid()
    Last edited by jcis; Feb 11th, 2012 at 11:05 AM.

  5. #5
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Degree minutes Second

    Matrik

    As Incidentals and Jcis have posted, Instr() and Mid() seem to be
    key functions. I'd add CInt() in my slightly different algo, as below:

    Code:
            txt = "60.3030"
            ' parse
            dot = InStr(txt, ".")           ' 3 = decimal's position in string
            txtdd = Mid(txt, 1, dot - 1)    ' "60" .. but can also handle 100+
            txtmmss = Mid(txt, dot + 1)     ' "3030"
            ' convert
            dd = CInt(txtdd)                ' 60
            mm = CInt(Left(txtmmss, 2))     ' 30
            ss = CInt(Right(txtmmss, 2))    ' 30
    The only caveat I'd add is that you be sure to use a leading "0" if
    minutes or seconds is less than 10, as in

    60 Degree, 9 minutes, 3 seconds .. entered as "60.0903"

    Note that Incidentals' use of Instr() already enables you
    to handle degrees less than 10 or over 100.

    Spoo

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