help with datetimepicker...

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 23
Reputation: gopi17 is an unknown quantity at this point 
Solved Threads: 0
gopi17 gopi17 is offline Offline
Newbie Poster

help with datetimepicker...

 
0
  #1
Oct 3rd, 2008
can some help me with this datetimepicker problem...
btime1 is my datetimepicker(format is time)

  1. Dim time559 As DateTime
  2. Dim time1001 As DateTime
  3. time559 = FormatDateTime("5:00:00 PM", DateFormat.LongTime)
  4. time1001 = FormatDateTime("10:01:00 PM", DateFormat.LongTime)
  5. If Btime1.Value < time559 And Btime1.Value > time1001 Then
  6. MsgBox("Booking Time is only available from 6.00 PM to 10.00 PM ")
  7. Rpanel1.Show()
  8. Else
  9. PListBox1.Items.Add("Customer Name" & ControlChars.Tab & _
  10. ControlChars.Tab & "Booking Date" & ControlChars.Tab & _
  11. ControlChars.Tab & "Booking Time")
  12. status1 = "Booked"
  13. Table1.BackColor = Color.Khaki
  14. PListBox1.Items.Add(Bcusname1.Text & ControlChars.Tab & _
  15. ControlChars.Tab & ControlChars.Tab & Bdate1.Value & ControlChars.Tab & _
  16. ControlChars.Tab & Btime1.Value)


the problem now is the first IF statement is not executing....i'm having trouble comparing them...can someone help me pls?

the allowed booking time is from 6pm to 10pm....somehow its not working..

thank u...
Last edited by gopi17; Oct 3rd, 2008 at 8:30 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 305
Reputation: timothybard is an unknown quantity at this point 
Solved Threads: 25
timothybard's Avatar
timothybard timothybard is offline Offline
Posting Whiz

Re: help with datetimepicker...

 
0
  #2
Oct 3rd, 2008
There are two problems:

1) In the If statement, the And should be Or.
2) Even if you change the Format property of the DateTimePicker to Time, the datetimepicker still stores the date. Therefore, the If statement is comparing 5:00 PM and 10:01 PM to, in my case 10/3/2008 6:00 PM. Because of the date part of the datetimepicker, the value in the date timepicker will always be larger than 10:01 PM.

Here is some code I put together to overcome these two issues:

  1. Dim time559 As DateTime
  2. Dim time1001 As DateTime
  3. Dim time1 As DateTime
  4. time559 = FormatDateTime("5:00:00 PM", DateFormat.LongTime)
  5. time1001 = FormatDateTime("10:01:00 PM", DateFormat.LongTime)
  6. time1 = FormatDateTime(Hour(btime1.Value) & ":" & Minute(btime1.Value))
  7. If time1 < time559 Or time1 > time1001 Then
  8. MsgBox("Booking Time is only available from 6.00 PM to 10.00 PM ")
  9. Else
  10. MsgBox("OK ")
  11. End If

Let me know if that works.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 23
Reputation: gopi17 is an unknown quantity at this point 
Solved Threads: 0
gopi17 gopi17 is offline Offline
Newbie Poster

Re: help with datetimepicker...

 
0
  #3
Oct 3rd, 2008
thank u soo much mr timoty...its working now..owe...one more question...can i do the exact same thing for the date...coz i need to compare the dates incase they want it 2molo or day after 2molo??....thank u soo much...
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 305
Reputation: timothybard is an unknown quantity at this point 
Solved Threads: 25
timothybard's Avatar
timothybard timothybard is offline Offline
Posting Whiz

Re: help with datetimepicker...

 
0
  #4
Oct 3rd, 2008
I don't know what comparisons you are trying to make, so here is some general code on how to get the selected date, today's date and tomorrow's date. You just need to create an If statement to make the comparisons you want.

  1. Dim chosenDate As Date
  2. Dim dateToday As Date
  3. Dim dateTomorrow As Date
  4.  
  5. chosenDate = FormatDateTime(DatePart(DateInterval.Month, btime1.Value) & "/" & DatePart(DateInterval.Day, btime1.Value) & "/" & DatePart(DateInterval.Year, btime1.Value), DateFormat.ShortDate)
  6. dateToday = FormatDateTime(Now, DateFormat.ShortDate)
  7. dateTomorrow = DateAdd(DateInterval.Day, 1, dateToday)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC