list box and the time in another list box. I wrote a simple function
that checks the times for duplicates. I wanted to check for a duplicate
before it writes to the listbox by returning a boolean (true/false)
value. I only need to check hours and minutes not date or seconds. The following is what I have, it's not recognizing the duplicates, am I confused in how the function reads? Any suggestions?
Expand|Select|Wrap|Line Numbers
- If (txtAppointment.Text = "") Then
- 'invalid input, alert user
- MessageBox.Show(Text:="You Must Enter an Appointment Description", _
- caption:="Input error - Add Appointment")
- 'select the invalid input
- txtAppointment.SelectAll()
- txtAppointment.Focus()
- Else
- Dim Time As Boolean
- Time = TimeTaken(Me.dtmTime.Value.ToShortDateString)
- If Time Then
- MessageBox.Show("You already have an appointment at this time")
- Else
- 'display appointment in Listbox
- lstApptResults.Items.Add(txtAppointment.Text)
- txtAppointment.Clear() 'clear appointment from TextBox
- txtAppointment.Focus() 'transfer focus to TextBox
- 'display appointment time in Listbox
- lstTimeResults.Items.Add(Me.dtmTime.Value.ToShortTimeString)
- End If
- End If
- End Sub 'btnAddAppt_Click
- 'function to check if an appointment time already exists in listbox
- Public Function TimeTaken(ByVal ApptTime As DateTime) As Boolean
- Dim DuplicateTime As Boolean = False
- 'loop that checks listed times for duplicates
- For Each strItem As String In lstTimeResults.Items
- If strItem = ApptTime Then
- DuplicateTime = True
- Exit For
- End If
- Next
- Return DuplicateTime
- End Function 'TimeTaken