Home All Groups Group Topic Archive Search About

Check for Duplicate Appointment Times

Author
13 Nov 2006 11:09 PM
geo039
I have a simple application that takes user input by text and time
selected by date time picker. It displays the appt description in one
list box and the time in another list box. I need a simple function
that checks the times for duplicates. I want to check for a duplicate
before it writes to the
listbox by returning a boolean (true/false) value I'm new to this so
any help would
be appreciated.

Thanks

Author
14 Nov 2006 4:55 AM
Cor Ligthert [MVP]
Geo,

At least for me it is not clear what you want, be aware that you seldom will
find a real equality in time values give by the date time picker because it
is (not real) accurate in milliseconds, therefore you should have to take a
time or a date part.

Cor

Show quoteHide quote
"geo039" <cassandrakl***@hotmail.com> schreef in bericht
news:1163459390.897430.138490@b28g2000cwb.googlegroups.com...
>I have a simple application that takes user input by text and time
> selected by date time picker. It displays the appt description in one
> list box and the time in another list box. I need a simple function
> that checks the times for duplicates. I want to check for a duplicate
> before it writes to the
> listbox by returning a boolean (true/false) value I'm new to this so
> any help would
> be appreciated.
>
> Thanks
>
Author
14 Nov 2006 4:29 PM
geo039
I'm only checking for hours and minutes not date or seconds. I'm
wondering if something like this would work but my only confusion lies
in the fact that we are dealing with date/time. It's not an integer or
a double?? Is it ByVal As Date, I don't know

Public Function DoesTimeExistInListBox(ByVal sometime As ???)
As Boolean
        Dim bExistsInListbox As Boolean = False


        For Each strItem As String In ListBox1.Items
            If strItem = sometime Then
                bExistsInListbox = True


                Exit For
            End If
        Next

        Return bExistsInListbox
    End Function
Author
14 Nov 2006 5:33 PM
Cor Ligthert [MVP]
DateTime

Cor

Show quoteHide quote
"geo039" <cassandrakl***@hotmail.com> schreef in bericht
news:1163521797.671141.11540@k70g2000cwa.googlegroups.com...
> I'm only checking for hours and minutes not date or seconds. I'm
> wondering if something like this would work but my only confusion lies
> in the fact that we are dealing with date/time. It's not an integer or
> a double?? Is it ByVal As Date, I don't know
>
> Public Function DoesTimeExistInListBox(ByVal sometime As ???)
> As Boolean
>        Dim bExistsInListbox As Boolean = False
>
>
>        For Each strItem As String In ListBox1.Items
>            If strItem = sometime Then
>                bExistsInListbox = True
>
>
>                Exit For
>            End If
>        Next
>
>        Return bExistsInListbox
>    End Function
>
Author
15 Nov 2006 3:29 PM
geo039
Right now I have this but it's not finding duplicates, I think there's
a problem with the function? Any Suggestions?

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
Author
15 Nov 2006 3:33 PM
rowe_newsgroups
>         For Each strItem As String In lstTimeResults.Items
>             If strItem = ApptTime Then

Could it be because you are comparing a string to a datetime? Perhaps
you should convert strItem to a datetime before running the comparison.
(or ApptTime to a string)

Thanks,

Seth Rowe


geo039 wrote:
Show quoteHide quote
> Right now I have this but it's not finding duplicates, I think there's
> a problem with the function? Any Suggestions?
>
> 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
Author
15 Nov 2006 9:39 PM
geo039
I tried this

For Each strItem As DateTime In lstTimeResults.Items
            If strItem = ApptTime Then

doesn't work either, i'm off to make sense of this exactstringmatch
business
Author
15 Nov 2006 6:27 PM
Cor Ligthert [MVP]
Geo,

Have a look in the findstringexact for the listbox.

http://lab.msdn.microsoft.com/search/refinement.aspx?__VIEWSTATE=&query=findstringexact

I hope this helps,

Cor

Show quoteHide quote
"geo039" <cassandrakl***@hotmail.com> schreef in bericht
news:1163604562.640596.78120@e3g2000cwe.googlegroups.com...
> Right now I have this but it's not finding duplicates, I think there's
> a problem with the function? Any Suggestions?
>
> 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
>