Results 1 to 7 of 7

Thread: case select problem

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    3

    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
    Kevin

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    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

  3. #3
    Lively Member
    Join Date
    Aug 2003
    Location
    Philadelphia, Pa.
    Posts
    123
    Convert the choices into datetime datatype.


    Code:
    Select Case cdate(ctime.Text)
    Case Is > cdate("11:00:00 PM") < cdate("11:59:00 PM")

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    3
    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
    Kevin

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    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?

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    3
    Thanks...I'll give that a try.
    Kevin

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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
  •  



Click Here to Expand Forum to Full Width