Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop for time(s) needed

Status
Not open for further replies.

HobbitK

Technical User
Jan 14, 2003
235
US
Hi everyone ..
I do not like the DTPicker control time. I would like to use a listbox instead. The project scope calls for 15 min. intervals from 7:00am to 5:00pm. I can not seem to figure out the syntax (or find a function) that would accomplish this.
Any suggestions?
Michael
 
why not use the timer control?

Known is handfull, Unknown is worldfull
 
Timer control is not what I need. Let me explain...
I am basically building a scheduling program for sales people in a company. They need to be able to select a date(currently using month view control) and times from 7am to 5pm for scheduled meetings. This is all to be used in their daily itenerary, and I just do not like the DTPicker controls time. I only need 15 min. intervals.
Thanks,
Michael
 
If you want a full 24 hrs at 15 min intervals, try this:

Dim lngCount As Long
For lngCount = 0 To 95
List1.AddItem Format(lngCount / 96, "hh:mm")
Next


You can of course restrict the range by changing the loop limits. eg 8:00 am to 5:00 pm would need:

For lngCount = 32 To 68

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
You could also use a VSroll and a label(or text box for direct input). The below will give you a range between 00:00 and 23:45, in increments of 15 Min.:

Option Explicit
Private StartTime As String

Private Sub Form_Load()
StartTime = TimeSerial(Hour(time), Round((Minute(time) / 15), 0) * 15, 0)
StartTime = Format$(StartTime, "hh:MM")

Label1.Caption = StartTime

With VScroll1
.SmallChange = 1
.LargeChange = 1
.Max = -1 * (CDate(StartTime) - CDate("00:00")) * 95
.Min = .Max + 95
End With

End Sub

Private Sub VScroll1_Change()
Label1.Caption = TimeSerial(Hour(StartTime), Minute(StartTime) + (15 * VScroll1.Value), 0)
End Sub

If you use a text box for direct input, you only need to format the text, after validating it as a date-time, as time and use the same formula as I did for calculating the initial StartTime (replacing the Time used for the Hour() & Minute() functions with the textbox value), and then calculate the new VScroll value as I also did, setting it to that.

You can do the same with the date selection.
 
If what you want is all the times from 7:00am to 5:00pm, in 15 minute increments, in a list box, try this:

Code:
Private Sub Command1_Click()
Dim dtmTime As Date
Dim strTime As String
dtmTime = "7:00am"
Do While (dtmTime < &quot;05:00 PM&quot;)
    strTime = Format(dtmTime, &quot;hh:mm AM/PM&quot;)
    List1.AddItem strTime
    dtmTime = DateAdd(&quot;n&quot;, 15, dtmTime)
Loop
End Sub

If you don't want 5:00pm to show up, just change the value in the loop condition to &quot;04:45 PM&quot;

tbuch
 
Thanks everyone ... looks like 3 perfect answers .. I will play with them all see which one fits best.
Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top