Jun 11, 2019 08:56 AM
(This post was last modified: Jun 11, 2019 08:57 AM by Ghostenigma.)
Hi!
I have this code and some data in listbox
And I get this result witch is what I want
https://imgur.com/a/rtpCtS7
But this code is getting results only from date 1 to 12 and is working
If i add a date from 13 to 31 I get an error
https://imgur.com/a/2BfgPU5[
What I have to change to get this code work if I check for each day of the month from 1-31?
I have this code and some data in listbox
Code
Dim attlist As New List(Of List(Of DateTime))
For i = 0 To 30
attlist.Add(New List(Of DateTime))
Next
For Each t As String In ListBox1.Items
For i = 1 To 31
If Convert.ToDateTime(t.Split(" "c)(0)).Month = i Then
attlist(i - 1).Add(t.Split(" "c)(0) & " " & t.Split(" "c)(t.Split(" "c).Length - 1))
End If
Next
Next
Dim p As Integer
For i = 0 To 30
If attlist(i).Count >= 2 Then
Dim checkin, checkout As String
checkin = ListBox1.Items(attlist(i).IndexOf(min(attlist(i))) + p)
checkout = ListBox1.Items(attlist(i).IndexOf(max(attlist(i))) + p)
Dim timestart, timeend As String
timestart = checkin.Substring(checkin.LastIndexOf(" "))
timeend = checkout.Substring(checkin.LastIndexOf(" "))
Dim ENDTIME As Date
Dim STARTTIME As Date
STARTTIME = timestart
ENDTIME = timeend
Dim TOTALTIME As TimeSpan
TOTALTIME = TimeSerial(Hour(ENDTIME), Minute(ENDTIME), Second(ENDTIME)) - TimeSerial(Hour(STARTTIME), Minute(STARTTIME), Second(STARTTIME))
ListBox2.Items.Add("On date " & ListBox1.Items(attlist(i).IndexOf(max(attlist(i))) + p).Split(" "c)(0) & " worked " & TOTALTIME.ToString("hh") & " hour e " + TOTALTIME.ToString("mm") & " minutes")
p += attlist(i).Count
End If
NextAnd I get this result witch is what I want
https://imgur.com/a/rtpCtS7
But this code is getting results only from date 1 to 12 and is working
If i add a date from 13 to 31 I get an error
https://imgur.com/a/2BfgPU5[
What I have to change to get this code work if I check for each day of the month from 1-31?


