NavList:
A Community Devoted to the Preservation and Practice of Celestial Navigation and Other Methods of Traditional Wayfinding
Re: Why do we still use this terrible Babylonian hexadecimal system
From: George Huxtable
Date: 2004 Nov 19, 10:15 +0000
From: George Huxtable
Date: 2004 Nov 19, 10:15 +0000
Mike Dorl wrote- >Is there anyway to use excel with dd mm ss data? > >I've been using the following macros to convert back and forth. To add >them to a sheet,use TOOLS - MACRO - VISUAL BASIC EDITOR. >Then after visual basic stars, do INSERT MODULE and paste them into the >resulting window. > >Mike > > >Function DMStoDEC(s As String) As Double > >Dim parts() As String > >Dim Degrees As Integer >Dim Minutes As Integer >Dim Seconds As Integer >Dim sign As Integer > >parts = Split(s, , , vbBinaryCompare) > >Degrees = parts(0) >If Degrees < 0 Then > sign = -1 > Degrees = -Degrees >Else > sign = 1 >End If > >Minutes = parts(1) >Seconds = parts(2) > >DMStoDEC = sign * (Degrees + Minutes / 60# + Seconds / 3600#) > >End Function > > >Function DECtoDMS(A As Double) As String > >Dim Degrees As Integer >Dim Minutes As Integer >Dim Seconds As Double > >Degrees = Int(A) >A = 60 * (A - Degrees) >Minutes = Int(A) >Seconds = 60# * (A - Minutes) >Seconds = Round(Seconds, 3) >Seconds = Int(Seconds * 1000#) >Seconds = Seconds / 1000# > >DECtoDMS = Degrees & " " & Minutes & " " & Seconds > >End Function ======================= Comment from George- Cliff Sojourner responded to my comments about a possible weakness in Chuck Taylor's angle conversion- "that's the first thing I checked in the VB code posted earlier; that one got it right too." I presume Cliff is referring to Mike Dorl's routine, quoted above But does Mike's routine get it right in all cases? I think I can see where it might break down. How will it cope with an angle that's -0deg 30'? The test for negative angle is made only on the degrees, not minutes or seconds. So, in that example, it has to make the test as to whether -0 is less than zero. I am unfamiliar with the Visual Basic that's in use here (my pocket calculator uses a much more rudimentary form of Bsic) but I suspect most computing programs will answer that it isn't less than zero, in which case Mike Dorl's program will fall down, treating an angle of -0deg 30' exactly the same as +0deg 30', to give +0.5 deg where it should have been -0.5 deg. A safer test for negativity might be to search for a "minus" character, somewhere in the string. Mike may have checked this aspect already, but if not he would be wise to try out his routine on an angle that's negative, and less than 1 degree. What's more, I have a strong suspicion that Mike's converse routine for degrees-to-dms will go wrong for any negative angle: I certainly recommend that he checks it out. Try converting -0.25deg, wich ought to give a result of -15'; I suspect that it will give -45'. I have become aware of such possible waywardness in angle conversion only by experience; in making such mistakes myself, then (the hard part) uncovering them, then (the easy part) correcting them. George. ================================================================ contact George Huxtable by email at george@huxtable.u-net.com, by phone at 01865 820222 (from outside UK, +44 1865 820222), or by mail at 1 Sandy Lane, Southmoor, Abingdon, Oxon OX13 5HX, UK. ================================================================