Finding duplicates before adding to listBox And synchronized scrollbars

dojoGirlaurora

New member
Joined
Apr 13, 2005
Messages
2
Programming Experience
5-10
I’m taking a beginning Visual Basic class. In the class we are writing an application that allows a user to enter a schedule of appointments and their times. I am having two problems with the application. The application is supposed to include a custom function called TimeTaken that returns the Boolean value true if the user enters a duplicate time value; the user is then to be notified by a message box. If TimeTaken returns false the appointment is added to the listBoxes. My first problem is that the application seems to jump over the message box area even if the two time values entered are the same. Could someone tell me if there's anything wrong with my logic? The solution would be easier if an array were used to store the previous times but we haven't reached arrays in my class. Here is my code:

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

'declare variables
Dim dtmAppointmentTime As Date 'holds user input of appointment time after validation
Dim strAppointment As String 'holds user input of appointment information
Dim dtmTakenTest As Date 'holds user input of appointment time before validation

'Call InputValidation Sub procedure
InputValidation(strAppointment, dtmAppointmentTime, dtmTakenTest)

'Call AppointmentDisplay Sub procedure
AppointmentDisplay(dtmAppointmentTime, strAppointment)

End Sub 'End btnAdd_Click
#Region "Custom Subs"

'this Sub procedure determines If a value has been entered in the txtAppointment textBox
'If no value has been entered a warning message box is displayed and the invalid text
'is selected
'Function TimeTaken is then called
'If time taken Returns True then a warning message box is displayed until the user
'selects a valid appointment time

Private Sub InputValidation(ByRef strAppointment As String, ByRef dtmAppointmentTime _
As Date, ByVal dtmTakenTest As Date)

'If no value has been entered in txtAppointment.Text
If txtAppointment.Text = "" Then

'display a warning
MessageBox.Show(Text:="A value must be entered for the appointment ", _
caption:="Input error: Empty Field")

'select invalid input
txtAppointment.SelectAll()
txtAppointment.Focus()

Else 'input is valid
'assign user input to a variable
strAppointment = txtAppointment.Text

End If 'End If

'If TimeTake is True
If TimeTaken(strAppointment, dtmAppointmentTime, dtmTakenTest) = True Then

'display Warning
MessageBox.Show(Text:="You already have an appointment at this time ", _
caption:="Cannot Add Appointment")

'select invalid input
dtpTime.Focus()

ElseIf TimeTaken(strAppointment, dtmAppointmentTime, dtmTakenTest) = False Then 'time is valid

'assign user input to variable
dtmAppointmentTime = dtmTakenTest

End If 'End If

End Sub 'End Sub InputValidation

'this Sub procedure converts output data into String format and displays it in
'the lstAppointments And lstTimes listBoxes

Private Sub AppointmentDisplay(ByVal dtmAppointmentTime As Date, ByVal strAppointment As String)

'declare private variables
Dim strDisplayOutput As String

'assign appointment time to String
strDisplayOutput = dtmAppointmentTime.ToString("hh:mm tt")

'display output in listBoxes
Me.lstAppointments.Items.Add(strAppointment)
Me.lstTimes.Items.Add(strDisplayOutput)



End Sub 'End Sub AppointmentDisplay

'this Function compares the new user input in dtpTime with the previous hour and minute
'values stored in dtmAppointmentTime.Hour and dtmAppointmentTime.Minute
'if a duplicate is found the Function Returns True

Private Function TimeTaken(ByRef strAppointment As String, ByRef dtmAppointmentTime _
As Date, ByRef dtmTakenTest As Date) As Boolean

'assign new input to dtmTakenTest
dtmTakenTest = dtpTime.Text

'If duplicate hours and minutes are found Return True
If ((dtmTakenTest.Hour = dtmAppointmentTime.Hour) And _
(dtmTakenTest.Minute = dtmAppointmentTime.Minute)) Then

Return True

Else 'new input is not a duplicate Return False

Return False

End If 'End If

End Function 'End Function TimeTaken

#End Region 'End Region Custom Subs


My second problem is that the output is displayed in two listBoxes. The data in the listBoxes so if one listBox is scrolled and the other remains stationary the output is incorrect. Is there anyway to make the listBox scrolling synchronized?
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,334
Location
Sydney, Australia
Programming Experience
10+
I have read over this code a few times and I can't find where you have assigned a value to dtmAppointmentTime before you compare it to dtmTakenTest. As far as I can see, the only place dtmAppointmentTime is assigned to is after TimeTaken has already returned True.
 
Top Bottom