For Loop and Time

telesphoreo

New Member
I want to be able to populate a whole dropdown list in as little code as possible.<BR><BR>Usually I would hardcode this. I have a starttime, an endtime and an interval.<BR><BR>We assume starttime is 7:30am and endtime is 17:15pm, I want this loop to populate my dropdownlist for every 15 minutes between those times, thus, 7:45 etc etc etc<BR><BR>I am using lstTime.Items.Insert(0, i) within my for loop, but I can't use any dates and only integers?<BR><BR>Thanks for your inputDim strFromTime As String<BR>Dim strToTime As String<BR>Dim intInterval As Integer<BR><BR>intInterval = 15<BR>strFromTime = #7:45 AM#<BR>strToTime = #5:15 PM#<BR><BR>Sub DropDown_Time()<BR><BR> Dim strTime As string<BR> Dim strTimeFrom As Date = strFromTime<BR> Dim strTimeTo As Date = strToTime<BR> Dim i As Integer<BR><BR> i = 0<BR> Do while strTimeFrom < strTimeTo<BR> strTime = DateAdd("N", intInterval, strTimeFrom)<BR> dropdown1.Items.Insert(i, strTime)<BR> strTimeFrom = strTime<BR> i = i + 1<BR> Loop<BR> dropdown1.SelectedIndex = 0<BR><BR> End Sub
 
Back
Top