Hack Forums
[.NET] Getting some ListBox items - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Getting some ListBox items (/showthread.php?tid=5978760)



Getting some ListBox items - Ghostenigma - Jun 11, 2019

Hi!

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
        Next

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?


RE: Getting some ListBox items - HFDone - Jun 11, 2019

The month component, expressed as a value between 1 and 12
https://docs.microsoft.com/en-us/dotnet/api/system.datetime.month?view=netframework-4.8


RE: Getting some ListBox items - Ghostenigma - Jun 11, 2019

(Jun 11, 2019 09:06 AM)HFDone Wrote:  The month component, expressed as a value between 1 and 12
https://docs.microsoft.com/en-us/dotnet/api/system.datetime.month?view=netframework-4.8
Yes but how to change that part to express the days(1-31) and not the months(1-12)?Because I've tried .Day but I still get that error


RE: Getting some ListBox items - HFDone - Jun 11, 2019

https://docs.microsoft.com/en-us/dotnet/api/system.datetime.day?view=netframework-4.8
Convert.ToDateTime("11/6/2019").Day


RE: Getting some ListBox items - Ghostenigma - Jun 11, 2019

(Jun 11, 2019 10:51 AM)HFDone Wrote:  https://docs.microsoft.com/en-us/dotnet/api/system.datetime.day?view=netframework-4.8
Convert.ToDateTime("11/6/2019").Day
Yes now is working because what I was doing wrong was the format of the date...I had it like dd:mm:yyyy but after changed to mm:dd:yyyy now it works!


I have another thing that I want to do

To add another for cycle to get each name on the listbox any tip would be appriciated


RE: Getting some ListBox items - HFDone - Jun 12, 2019

you can grab it with your code t.Split(" "c)(1)