473,498 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Time Check Function

geo039
47 New Member
I tried to write 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 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
  1. If (txtAppointment.Text = "") Then
  2.             'invalid input, alert user
  3.             MessageBox.Show(Text:="You Must Enter an Appointment Description", _
  4.                 caption:="Input error - Add Appointment")
  5.             'select the invalid input
  6.             txtAppointment.SelectAll()
  7.             txtAppointment.Focus()
  8.  
  9.         Else
  10.  
  11.             Dim Time As Boolean
  12.  
  13.             Time = TimeTaken(Me.dtmTime.Value.ToShortDateString)
  14.  
  15.             If Time Then
  16.                 MessageBox.Show("You already have an appointment at this time")
  17.             Else
  18.  
  19.             'display appointment in Listbox
  20.                 lstApptResults.Items.Add(txtAppointment.Text)
  21.                 txtAppointment.Clear() 'clear appointment from TextBox
  22.                 txtAppointment.Focus() 'transfer focus to TextBox
  23.  
  24.             'display appointment time in Listbox
  25.                 lstTimeResults.Items.Add(Me.dtmTime.Value.ToShortTimeString)
  26.  
  27.             End If
  28.         End If
  29.     End Sub 'btnAddAppt_Click
  30.     'function to check if an appointment time already exists in listbox
  31.     Public Function TimeTaken(ByVal ApptTime As DateTime) As Boolean
  32.  
  33.         Dim DuplicateTime As Boolean = False
  34.  
  35.         'loop that checks listed times for duplicates
  36.         For Each strItem As String In lstTimeResults.Items
  37.             If strItem = ApptTime Then
  38.                 DuplicateTime = True
  39.  
  40.                 Exit For
  41.             End If
  42.         Next
  43.  
  44.         Return DuplicateTime
  45.     End Function 'TimeTaken
Nov 14 '06 #1
4 2126
Lok
11 New Member
Expand|Select|Wrap|Line Numbers
  1. If (txtAppointment.Text = "") Then
  2.             'invalid input, alert user
  3.             MessageBox.Show(Text:="You Must Enter an Appointment Description", _
  4.                 caption:="Input error - Add Appointment")
  5.             'select the invalid input
  6.             txtAppointment.SelectAll()
  7.             txtAppointment.Focus()
  8.  
  9.         Else
  10.  
  11.             Dim Time As Boolean
  12.  
  13.             Time = TimeTaken(Me.dtmTime.Value.ToShortDateString)
  14.  
  15.             If Time Then
  16.                 MessageBox.Show("You already have an appointment at this time")
  17.             Else
  18.  
  19.             'display appointment in Listbox
  20.                 lstApptResults.Items.Add(txtAppointment.Text)
  21.                 txtAppointment.Clear() 'clear appointment from TextBox
  22.                 txtAppointment.Focus() 'transfer focus to TextBox
  23.  
  24.             'display appointment time in Listbox
  25.                 lstTimeResults.Items.Add(Me.dtmTime.Value.ToShortTimeString)
  26.  
  27.             End If
  28.         End If
  29.     End Sub 'btnAddAppt_Click
  30.     'function to check if an appointment time already exists in listbox
  31.     Public Function TimeTaken(ByVal ApptTime As DateTime) As Boolean
  32.  
  33.         Dim DuplicateTime As Boolean = False
  34.  
  35.         'loop that checks listed times for duplicates
  36.         For Each strItem As String In lstTimeResults.Items
  37.             If strItem = ApptTime Then
  38.                 DuplicateTime = True
  39.  
  40.                 Exit For
  41.             End If
  42.         Next
  43.  
  44.         Return DuplicateTime
  45.     End Function 'TimeTaken

Try to investigate whether the parameter value that you sent to the TimeTaken function is what you expected (eg. put a MsgBox or something to inspect the value).

I don't have chance to try it, but so far from what I'm read your code, that your listbox items are string. Your time-input is also a string (gained from .ToShortTimeString). But why your TimeTaken parameter type is a DateTime ?

When the program run, the original time entered by the user will be convert to a string using .ToShortTimeString, the when passed to the TimeTaken function, it will converted back to DateTime. Then when compared to the listbox items, it will converted again to a string (using DateTime default format).

Don't know, maybe it's the root of the problem. Please check.

regards,
Lok
Nov 15 '06 #2
geo039
47 New Member
I think the conversion is where I am confused. The user writes their appt in a text box and selects a time from a datetimepicker. The input from text goes to one list box and the time to another. I want to check against the times only but somewhere along the lines it's not checking the time as a time. The functionality works the function just isn't picking up the time as a format needing to check for duplicates for some reason.
Nov 15 '06 #3
Lok
11 New Member
Ok, then make it in the same format then, avoid any conversion. So you must be firm, decide one, keep it as a string, or as a DateTime.

As a string, after user pick the DateTime using DatePicker, convert it to string. Put inside listbox (also as a string), then when you want to compare, compare it also string to string.

As a DateTime, after user pick the DateTime using DatePicker, convert it to string (why? it's the easiest way to populate listbox), then when you want to compare, get the item from the listbox, convert it back to DateTime, then compare it DateTime to DateTime.

If you want to put more effort, create a custom ListBoxItem class, overriding its ToString() method (a string value with specific date/time format that you required). So you can still keep the original DateTime value to be use for comparison.

Regards,

Lok
Nov 16 '06 #4
geo039
47 New Member
Got the simple problem to work. Sometimes after all is said and done the solution ends up being something so simple. After staring at something for hours it all just starts to go to mush.

Thanks Again
Nov 16 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2682
by: Dave | last post by:
Hi I am hoping someone might be able to help me out with this. I am writing a helpdesk system which records agents logging in and out of the system. I need to write a stored procedure which...
6
2497
by: Kenneth | last post by:
Hello, I'm having some serious problems debugging a script that I'm trying to make work. I'm working on a form where a user can type in a time (in the format of HH:MM), and another script...
5
9070
by: Erich Schreiber | last post by:
In the Python Library Reference the explanation of the time.sleep() function reads amongst others: > The actual suspension time may be less than that requested because > any caught signal will...
11
7958
by: zhong | last post by:
Error Message: Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention...
8
10149
by: Antony | last post by:
compiler£ºVisual Studio.Net 2003 (VC7.1) compile type£ºDebug problem: wanted more information about the "Run-Time Check Failure #n",thanks! Example1: #include "stdafx.h" void malice() {...
11
4049
by: Dirntknow | last post by:
Further to my recent post in this newsgroup i've got to admit i'm struggling. I've no experience with javascript or it's workings. What i'd like is a simple converter to allow a user to input the...
2
9896
by: wizard | last post by:
Hello Friends, There is a PHP function checkdate to check if a date is a valid Gregorian date. Is there any such function to check for a valid time like something in hh:mm:ss format? If not, can...
12
2728
by: Ioannis Vranos | last post by:
Perhaps a mechanism can be introduced in the C++0x/1x standard, something simple like defining a function as: void somefunc(void) throw() { // ... }
25
4509
by: Brian | last post by:
I have a datetimepicker formated for just time, the user selects the time. I want to compare if that time is between midnight and 8 am dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM# this...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.