|
-
May 25th, 2004, 02:40 PM
#1
Thread Starter
New Member
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
-
May 25th, 2004, 02:54 PM
#2
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
-
May 25th, 2004, 02:56 PM
#3
Lively Member
Convert the choices into datetime datatype.
Code:
Select Case cdate(ctime.Text)
Case Is > cdate("11:00:00 PM") < cdate("11:59:00 PM")
-
May 25th, 2004, 03:30 PM
#4
Thread Starter
New Member
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
-
May 25th, 2004, 03:34 PM
#5
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?
-
May 25th, 2004, 03:40 PM
#6
Thread Starter
New Member
Thanks...I'll give that a try.
-
May 26th, 2004, 04:29 AM
#7
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|