Newsgroup: it.comp.lang.visual-basic
Titolo: select case won't work

Can someone tell me why this Case doesn't work?
TODAY = "Wed"
DAYTIME = "17:00"
' shipping date
    today = Format(Date, "ddd") ' abbreviated name of day
    daytime = Format(Time, "hh:mm")
    Select Case today
        Case today = "Sat"
            sb = Date + 2
        Case today = "Sun"
            sb = Date + 1
        Case today = "Mon", "Tue", "Wed", "Thu"
            Select Case daytime
                Case daytime < "14:00"
                    sb = Date
                Case daytime >= "14:00"
                    sb = Date + 1
            End Select
        Case today = "Fri"
            Select Case daytime
                Case daytime < "14:00"
                    sb = Date
                Case daytime >= "14:00"  ' <<------- THIS IS TRUE BUT...
                    sb = Date + 1 '<<-------------------- THIS DOESN'T EXECUTE.
            End Select
    End Select
Note:  A simple If/Them clause works.

,

The problem with the code you posted is that you are using the Select Case
statement incorrectly.  Check the help for for the correct usage.  Either of
the follow methods will work.
    '******************************************************************
    today = Format(Date, "ddd") ' abbreviated name of day
    daytime = Format(Time, "hh:mm")
    Select Case today
        Case "Sat"
            sb = Date + 2
        Case "Sun"
            sb = Date + 1
        Case "Mon", "Tue", "Wed", "Thu"
            Select Case daytime < "14:00"
                Case True
                    sb = Date
                Case False
                    sb = Date + 1
            End Select
        Case "Fri"
            Select Case daytime < "14:00"
                Case True
                    sb = Date
                Case False          ' <<------- THIS IS TRUE BUT...
                    sb = Date + 1   ' <<------- THIS DOESN'T EXECUTE.
            End Select
    End Select
    '******************************************************************
    today = Format(Date, "ddd") ' abbreviated name of day
    daytime = Format(Time, "hh:mm")
    Select Case today
        Case "Sat"
            sb = Date + 2
        Case "Sun"
            sb = Date + 1
        Case "Mon", "Tue", "Wed", "Thu"
            Select Case daytime
                Case Is < "14:00"
                    sb = Date
                Case Is >= "14:00"
                    sb = Date + 1
            End Select
        Case "Fri"
            Select Case daytime
                Case Is < "14:00"
                    sb = Date
                Case Is >= "14:00" ' <<------- THIS IS TRUE BUT...
                    sb = Date + 1   '<<------- THIS DOESN'T EXECUTE.
            End Select
    End Select
    '******************************************************************
Three comments... 1.  Since you are doing the same thing in the "Fri" case as
in the the "Mon" through "Thu" case, why not incorporate "Fri" code into the
"Mon" through "Thu" code?
2.  Notice that you don't need to say 'today = "Sat"' since 'today' is your
test expression.
3.  Your Select Case that checks 'daytime' could be coded with an if statement
     if daytime < "14:00" then
         sb = Date
     else
         sb = Date + 1
     end if
Hope this helps you out.
Noel
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/
       Search, Read, Discuss, or Start Your Own