Juggler_IN
Active Member
 Joined
 Nov 19, 2014
 Messages
 264
 Platform

 Windows
With the VBA converted code for the code at stackoverflow link Time Angles. I am able to output first two results correctly. But the third result output is not as expected.
For example, for time 11:54:29 the expected results are Hourminute hands =30.34, Minutesecond hands =152.90, and Secondhour hands =176.76.
The current output from udf is:
' HourMinute = 30.34166  CORRECT
' MinuteSecond = 152.90  CORRECT
' SecondHour = 183.24166  INCORRECT
Any possible fix?
For example, for time 11:54:29 the expected results are Hourminute hands =30.34, Minutesecond hands =152.90, and Secondhour hands =176.76.
The current output from udf is:
' HourMinute = 30.34166  CORRECT
' MinuteSecond = 152.90  CORRECT
' SecondHour = 183.24166  INCORRECT
VBA Code:
Function AngleOfTime(x As Date, i As Integer) As Double
Dim h%, m%, s%, u, v, w
h = Hour(x)
m = Minute(x)
s = Second(x)
u = ((6 * m) + ((1 / 60 * 6) * s)) ' Angle of the minute hand.
v = ((30 * h) + (0.5 * (m + s / 60))) ' Angle of the hour hand.
w = (6 * s) ' Angle of the second hand.
If i = 1 Then
AngleOfTime = Abs(v  u) ' Hourminute Angle
ElseIf i = 2 Then
AngleOfTime = Abs(u  w) ' Minutesecond Angle
ElseIf i = 3 Then
AngleOfTime = Abs(w  v) ' Secondhour Angle
Else
AngleOfTime = 0
End If
End Function
Any possible fix?