HtoM function

Started by nico18n, November 13, 2019, 04:43:04 AM

Previous topic - Next topic

nico18n

MrBcx,

Thank you for the tip.
Cheers
I like programming. I like BCX :-)

MrBcx

Nico,

There is no built-in function in BCX that does what your function is accomplishing.


I am sharing two functions that I used throughout my career that converts Decimal Degrees to Degrees-Minutes-Seconds and vice-versa.

DD.dddddddd  (DD is the integer portion of the Degree (or HOUR) and .ddddddd is the fractional portion

DD.MMSSddddd (DD is the integer portion of the Degree (or HOUR), MM is the Minutes (0 to 60), SS is the SECONDS(0 to 60) and dddd is any fractional portion of a second.

You can think of DEGREES being the same as HOURS.

In fact, many of the HP calculators had HR->HMS  and HMS->HR conversion buttons



FUNCTION Dms2Deg (Angle AS DOUBLE) AS DOUBLE
LOCAL Deg AS DOUBLE
LOCAL Msc AS DOUBLE
LOCAL MIN AS DOUBLE
LOCAL Sec AS DOUBLE
Angle = Angle + Angle * 1E-16
Deg = FIX (Angle)
Msc = 100.0 * (Angle - Deg)
MIN = FIX (Msc)
Sec = 100.0 * (Msc - MIN)
FUNCTION = Deg + (MIN / 60.0) + (Sec / 3600.0)
END FUNCTION





FUNCTION Deg2Dms (Angle AS DOUBLE) AS DOUBLE
LOCAL Deg AS DOUBLE
LOCAL Msc AS DOUBLE
LOCAL MIN AS DOUBLE
LOCAL Sec AS DOUBLE
Angle = Angle + Angle * 1E-16
Deg = FIX (Angle)
Msc = 60.0 * (Angle - Deg)
MIN = FIX (Msc)
Sec = 60.0 * (Msc - MIN)
IF (Sec > 59.9999) THEN
  MIN = MIN + 1.0
  Sec = 0
END IF
FUNCTION = Deg + (MIN / 100.0) + (Sec / 10000.0)
END FUNCTION



nico18n

#1
A small question...

I made this sub to transform the hours into minutes. Is there a function in BCX that does it already?

function HtoM(Hr as string) as int   '--- Hr for example is 10.25
   local i as int
   dim r$[2]
   i = split(r$, Hr, ".")
   function = VAL(r$[0])*60 + VAL(r$[1])
end function

Cheers
I like programming. I like BCX :-)