-
Mar 1st, 2018, 06:51 AM
#1
Listbox with Time Interval
Hi,
what would be the best way to create a Time-Intervall (15min; 30min.etc..)
I created a checkedlistbox from 00:00 to 24:00
but I would alse like to select ..say 08:00 till 18:00.
any Ideas
here my code..
Code:
Public Class Form1
Private Shared Function GetTimeList(ByVal minutesInterval As Int32) As IList(Of String)
Dim retVal As List(Of String)
Dim dt As DateTime
dt = New DateTime(1, 1, 1, 0, 0, 0)
retVal = New List(Of String)(24 * 60 / minutesInterval)
While dt.Day < 2
retVal.Add(dt.ToString("HH:mm"))
dt = dt.AddMinutes(minutesInterval)
End While
Return (retVal)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CheckedListBox1.DataSource = GetTimeList(30)
End Sub
End Class
regards
Chris
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Mar 1st, 2018, 07:13 AM
#2
Re: Listbox with Time Interval
I would tend to do this:
vb.net Code:
Function GetTimeList(timeInterval As Integer) As String() Dim times As New List(Of TimeSpan) Dim time = TimeSpan.Zero Dim interval = TimeSpan.FromMinutes(timeInterval) Dim maxTime = TimeSpan.FromHours(24) Do times.Add(time) time = time.Add(interval) Loop While time < maxTime Return times.Select(Function(ts) ts.ToString("hh\:mm")).ToArray() End Function
I'm not sure what this means:
but I would alse like to select ..say 08:00 till 18:00.
-
Mar 1st, 2018, 07:32 AM
#3
Re: Listbox with Time Interval
Hi,
it is for a scheduler, each User can create the own -Timegrid- and how many rows they want in the scheduler for a specific time.
the -Timegrid- they put together is then saved to a Database table
here a Image
EDIT: this is a VB6 program
should give you an idea.
regards
Chris
Last edited by ChrisE; Mar 1st, 2018 at 07:38 AM.
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Mar 1st, 2018, 11:33 AM
#4
Re: Listbox with Time Interval
I've seen this done in JS, but in that case, there was just a list by 15 minute intervals. With the listbox (checked or not), it looks like you aren't trying to set a start and end so much as selecting which of the intervals within the range are desired. I would prefer not to use a checked listbox for this, as I find them to not always work the way I want. The selection mode should allow you to do what you are seeking as far as selecting a range within a larger range. After all, you pretty much described multi select extended.
However, I'm not clear on what the actual question is. You seem to have a viable solution, and JMC may, as well, but it seems to me that this is more a design issue than a coding issue. For example, I wouldn't want the user to have too much flexibility as to what intervals they can use. You may not be allowing this already. After all, a day or hour can only be reasonably divided up into certain sized chunks (factors of 24 or 60). As long as you know that, you don't necessarily have to store the times anywhere. For example, if you were to divide up the hours into 15 minute intervals, then you might store just 4 (number of divisions within each hour), and the start and end interval in the day. The number of intervals would be (24 * divisions per hour), so if you then stored a start interval of 23, and an end interval of 71, you could recreate the range 8:00 to 18:00, and all you'd be storing would be three integers.
My usual boring signature: Nothing
-
Mar 1st, 2018, 12:17 PM
#5
Re: Listbox with Time Interval
Originally Posted by Shaggy Hiker
I've seen this done in JS, but in that case, there was just a list by 15 minute intervals. With the listbox (checked or not), it looks like you aren't trying to set a start and end so much as selecting which of the intervals within the range are desired. I would prefer not to use a checked listbox for this, as I find them to not always work the way I want. The selection mode should allow you to do what you are seeking as far as selecting a range within a larger range. After all, you pretty much described multi select extended.
However, I'm not clear on what the actual question is. You seem to have a viable solution, and JMC may, as well, but it seems to me that this is more a design issue than a coding issue. For example, I wouldn't want the user to have too much flexibility as to what intervals they can use. You may not be allowing this already. After all, a day or hour can only be reasonably divided up into certain sized chunks (factors of 24 or 60). As long as you know that, you don't necessarily have to store the times anywhere. For example, if you were to divide up the hours into 15 minute intervals, then you might store just 4 (number of divisions within each hour), and the start and end interval in the day. The number of intervals would be (24 * divisions per hour), so if you then stored a start interval of 23, and an end interval of 71, you could recreate the range 8:00 to 18:00, and all you'd be storing would be three integers.
Hi,
I came up with this, more or less the same from VB6
the users can pick what the want for there Timegrid, still a lot to do...
here the code if you want to try.
Code:
Option Strict On
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'set hours
For i = 0 To 23
CheckedListBox1.Items.Add("hours " & Format(i, "00"))
Next
CheckedListBox1.SetItemChecked(8, True)
'set minutes
With CheckedListBox2
For i = 0 To 55 Step 5
.Items.Add("minutes " & Format(i, "00"))
Next
For i = 1 To .Items.Count - 1 Step 3
.SetItemChecked(CInt(i), True)
Next i
End With
'set rows
CheckedListBox3.Items.Add("1 row")
For i = 2 To 5
CheckedListBox3.Items.Add(i & " rows")
Next
CheckedListBox3.SetItemChecked(1, True)
' fixed Timegrid
For i = 8 To 17
ListBox1.Items.Add(Format(i, "00") & ":00 2 rows")
ListBox1.Items.Add(Format(i, "00") & ":30 2 rows")
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For Each s As String In CheckedListBox1.CheckedItems
For Each f As String In CheckedListBox2.CheckedItems
For Each g As String In CheckedListBox3.CheckedItems
ListBox2.Items.Add(s.Substring(s.Length - 2) & ":" & f.Substring(f.Length - 2) & " " & g)
Next
Next
Next
End Sub
End Class
regards
Chris
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|