Incrementing time, but not 'Now'

Cobalt

Member
Joined
May 28, 2008
Messages
21
Programming Experience
3-5
Hi Guys,

I hope you can help me with this simple little problem that I just can't get around! It's driving me nuts, as I sure there is an easy way to do it.

I'm looking to output in some way (messagebox, textbox, listbox etc) times starting from 8am all the way to 9pm in set increments (30, 15 mins etc)

I first tried this nasty bit of code below, until I figured out that integers get rounded...

VB.NET:
Dim startTime As Integer
        Dim endTime As Integer
        Dim increment As Integer

        startTime = 8.0
        endTime = 21.0
        increment = 0.3

        While startTime < endTime

            listbox1.items.add(startTime)
            startTime = startTime + increment
            If (startTime + 0.4) = (startTime + 1) Then
                startTime = startTime + 1

            End If

        End While

I then tried with doubles, but found it too detailed. I'm sure there must be a way to get this done with Date, but I don't really want to deal with incrementing 'Now' times, only selected hours. I'm missing something obvious aren't I?

I would like to have the start, end, and increments as variables so I can vary my times as well.

Thanks for the help, try and be gentle with a muppet question such as this!

Cheers! :)
 
VB.NET:
Dim d as DateTime = DateTime.Now.Date.AddHours(8)

While d < DateTime.Now.Date.AddHours(21)
  d = d.AddMinutes(30)
  MessageBox.Show(d)
End While
 
Back
Top