I am trying to calculate the time durations via the below Sub
. But it takes only two iterations.where as it should take 4
, as a result all the durations are not being summed up.I introduced 2
msgbox
- which are showing the result. Fitst one showing the length which is perfect,but the second one showing some thing undesired.
CODE
msgbox(ArrayListTaskDetails.Count) '~~ output is 16
For IndexSearch = 0 To ArrayListTaskDetails.Count - 1 Step 4
dt1 = ArrayListTaskDetails(IndexSearch + 3)
SumDate = TimeAdd(dt1,SumDate)
If Err Then
msgbox(IndexSearch) '~~ output as 8. here is the question why the error occurs?
Err.Clear
Exit for
End If
Next
Function TimeAdd(dt1,dt2)
If (IsDate(Cdate(dt1)) And IsDate(Cdate(dt2))) = False Then ' `Type mismatch: Cdate` error occurs in this line. Could you guide me here where the wrong is?
TimeAdd = "00:00:00"
Exit Function
End If
TimeAdd = Hour(dt1)+Hour(dt2) & ":" & Minute(dt1)+Minute(dt2) & ":" & Second(dt1)+Second(dt2)
End Function
Note: Time duration are 00:05:23
,00:11:58
,195:33:12
,320:37:13
respectively at 3,7,11,15 th position of the List