0

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

4

1 回答 1

1

The IsDate function returns a Boolean value that indicates if the evaluated expression can be converted to a date. It returns True if the expression is a date or can be converted to a date; otherwise, it returns False.Link here

Code should be as :-

If Not (IsDate((dt1) And IsDate(dt2)) Then            '' If dt1 or dt2, any one from this id not date then it will set timeAdd = "00:00:00"
   TimeAdd = "00:00:00"
   Exit Function
End If
于 2013-01-02T07:34:56.677 回答