Hello All,

I have 3 combo boxes on my form

1. Doctor Start Time
2. Doctor End Time
3. Doctor Appointment Duration

I want a 4th combo Box that will Start from Doctor's Start Time upto Doctor's End Time with the interval of Appointment Duration

eg. Suppose the Start time is 08:00 and End Time 10:00 with 24 hr clock
the appointment duration is 30 mins

then the 4th comboBox should Display
08:00
08:30
09:00
09:30

Can anyone help me in this

I have done this coding on the basis of Appointment Duration

``````Dim da As DateTime = FormatDateTime("00:00")
cboAppTime.Items.Clear()
If txtDuration.Text = "15" Then
For xa As Integer = 0 To 95
Next
ElseIf txtDuration.Text = "30" Then
For xa As Integer = 0 To 47
Next
ElseIf txtDuration.Text = "45" Then
For xa As Integer = 0 To 31
Next
ElseIf txtDuration.Text = "60" Then
For xa As Integer = 0 To 23
Next
End If``````

The above coding shows time from 00:00 to 23:00

Need to proceed further with ur help.

Answered by Pgmer 50 in a post from

See if this helps u...

``````Try
Dim starttime As New DateTime
Dim endtime As New DateTime
Dim duration As New TimeSpan
endtime = DateTimePicker2.Text
starttime = DateTimePicker1.Text
duration = TimeValue(DateTimePicker2.Text) - TimeValue(DateTimePicker1.Text)
Dim Dur As Integer = duration.Hours
Dur = (Dur * 60) / 30

For i …``````

## All 4 Replies

See if this helps u...

``````Try
Dim starttime As New DateTime
Dim endtime As New DateTime
Dim duration As New TimeSpan
endtime = DateTimePicker2.Text
starttime = DateTimePicker1.Text
duration = TimeValue(DateTimePicker2.Text) - TimeValue(DateTimePicker1.Text)
Dim Dur As Integer = duration.Hours
Dur = (Dur * 60) / 30

For i As Integer = 0 To Dur - 1

Next

Catch ex As Exception

End Try``````

Rather than calculating the Duration possibly

``````appointmentTime = starttime
do until appointmentTime >= endtime
loop``````

note that if Appointment duration does not divide evenly the last appointment will overrun the end time. If this is not acceptable you will need to add the AppointmentDuration to the endTime in the until clause

See if this helps u...

``````Try
Dim starttime As New DateTime
Dim endtime As New DateTime
Dim duration As New TimeSpan
endtime = DateTimePicker2.Text
starttime = DateTimePicker1.Text
duration = TimeValue(DateTimePicker2.Text) - TimeValue(DateTimePicker1.Text)
Dim Dur As Integer = duration.Hours
Dur = (Dur * 60) / 30

For i As Integer = 0 To Dur - 1

Next

Catch ex As Exception

End Try``````

This code has helped me a lot...but only one problem....

I want the output in a 24 hr format
and this way

08:00
08:30
.
.
.
.
.
.
12:30
13:00
13:30

How can I proceed with this???

This code has helped me a lot...but only one problem....

I want the output in a 24 hr format
and this way

08:00
08:30
.
.
.
.
.
.
12:30
13:00
13:30

How can I proceed with this???

``````Try
cboDays.Items.Clear()
Dim starttime As DateTime = FormatDateTime("00:00")
Dim endtime As DateTime = FormatDateTime("00:00")
Dim duration As New TimeSpan
endtime = TextBox2.Text
starttime = TextBox1.Text
duration = TimeValue(TextBox2.Text) - TimeValue(TextBox1.Text)
Debug.Print("endtime: " + endtime)
Debug.Print("starttime: " + starttime)
Debug.Print("duration: " + duration.ToString)
Dim Dur As Integer = duration.Hours
Dim Dura As Integer = Integer.Parse(cboTime.Text)
Do Until starttime >= endtime