-
case select problem
can anyone help me with this code...none of the cases are showing true except the CaseElse...Thanks everyone for your help...
Select Case ctime.Text
Case Is > "11:00:00 PM" < "11:59:00 PM"
snowwagerstatussleep.Visible = True
snowwagerstatusawake.Visible = False
Case Is > "5:00:00 PM" < "10:59:59 PM"
snowwagerstatussleep.Visible = False
snowwagerstatusawake.Visible = True
Case Is > "3:00:00 PM" < "4:59:59 PM"
snowwagerstatussleep.Visible = True
snowwagerstatusawake.Visible = False
Case Is > "8:00:00 AM" < "2:59:59 PM"
snowwagerstatussleep.Visible = False
snowwagerstatusawake.Visible = True
Case Is > "7:00:00 AM" < "7:59:59 AM"
snowwagerstatussleep.Visible = True
snowwagerstatusawake.Visible = False
Case Is > "12:00:00 AM" < "6:59:59 AM"
snowwagerstatussleep.Visible = False
snowwagerstatusawake.Visible = True
Case Else
-
Doing strings to string comparisons on numbers has problems...
1: is between 12: and 6: - stuff like that. The 12 and 6 are bad anyway - 12 is a higher number than 6.
The AM and PM changes the value of the HOUR dramatically, but it's at the end of the string.
Can you make the strings "military time"?
Then you need to pad the HOURS with a leading 0 to get the 1: to be 01:
That should get you headed in the right direction
-
Convert the choices into datetime datatype.
Code:
Select Case cdate(ctime.Text)
Case Is > cdate("11:00:00 PM") < cdate("11:59:00 PM")
-
Thanks for you help. I'm not sure how to change everything to military time...I added CDate() to everything now its stoping on the first case during break point...
Code:
Select Case CDate(ctime.Text)
Case Is > CDate("11:00:00 PM") < CDate("11:59:00 PM")
snowwagerstatussleep.Visible = True
snowwagerstatusawake.Visible = False
its only 2:29PM here
-
I like the CDATE idea that Smeagol posted...
SELECT CASE takes the first, and only the first, CASE that applies, so how about putting this first:
CASE IS < CDate("7:00 AM")
Then put:
CASE IS < CDate("8:00 AM")
and so on...
BTW - you do really want 7:00 and 8:00, not 6:59 and 7:59 - right?
-
Thanks...I'll give that a try.
-
There is an error in your case statements which nobody else has mentioned:
Case Is > "11:00:00 PM" < "11:59:00 PM"
is interpreted by VB as:
Case Is > ("11:00:00 PM" < "11:59:00 PM")
which is the same as:
Case Is > True
szlamany's answer will solve this problem.