Juggler_IN
Active Member
- Joined
- Nov 19, 2014
- Messages
- 358
- Office Version
- 2003 or older
- 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 Hour-minute hands =30.34, Minute-second hands =152.90, and Second-hour hands =176.76.
The current output from udf is:
' Hour-Minute = 30.34166 -- CORRECT
' Minute-Second = 152.90 -- CORRECT
' Second-Hour = 183.24166 -- INCORRECT
Any possible fix?
For example, for time 11:54:29 the expected results are Hour-minute hands =30.34, Minute-second hands =152.90, and Second-hour hands =176.76.
The current output from udf is:
' Hour-Minute = 30.34166 -- CORRECT
' Minute-Second = 152.90 -- CORRECT
' Second-Hour = 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) ' Hour-minute Angle
ElseIf i = 2 Then
AngleOfTime = Abs(u - w) ' Minute-second Angle
ElseIf i = 3 Then
AngleOfTime = Abs(w - v) ' Second-hour Angle
Else
AngleOfTime = 0
End If
End Function
Any possible fix?