Case statement

Discussion in 'ASP General' started by Dave, Jan 29, 2004.

  1. Dave

    Dave Guest

    I am getting a syntax error on

    Select Case Now
    Case > "2/2/2004 12:30:00 AM"
    response.redirect "votingover.asp"
    case else
    m=0
    End Select
     
    Dave, Jan 29, 2004
    #1
    1. Advertising

  2. Dave

    Bob Barrows Guest

    Dave wrote:
    > I am getting a syntax error on
    >
    > Select Case Now
    > Case > "2/2/2004 12:30:00 AM"
    > response.redirect "votingover.asp"
    > case else
    > m=0
    > End Select


    You're comparing a date to a string. Date literals need to be delimited by
    hash marks (#):
    Case > #2/2/2004 12:30:00 AM#

    You can also use CDate to do the conversion:

    Case > CDate("2/2/2004 12:30:00 AM")

    HTH,
    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows, Jan 29, 2004
    #2
    1. Advertising

  3. Dave

    Ray at Guest

    The select case statement in vbscript isn't as versatile as that in VB. Try
    this:


    Dim sNow
    sNow = Now

    Select Case True
    Case DateValue(sNow) > DateValue("2/2/2004 12:30:00 AM")
    Response.Redirect "votingover.asp"
    Case Else
    Response.Write "fine"
    m=0
    End Select

    Ray at home

    "Dave" <> wrote in message
    news:%...
    > I am getting a syntax error on
    >
    > Select Case Now
    > Case > "2/2/2004 12:30:00 AM"
    > response.redirect "votingover.asp"
    > case else
    > m=0
    > End Select
    >
    >
     
    Ray at, Jan 29, 2004
    #3
  4. Dave

    Bob Barrows Guest

    Oops. The error message mislead me. Now if he had told us that the error
    message was "syntax error", ...

    Of course, this works as well (I tested it this time :) ):
    Select Case True
    Case Now > #1/2/2004 12:30:00 AM#

    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"

    Ray at <%=sLocation%> wrote:
    > The select case statement in vbscript isn't as versatile as that in
    > VB. Try this:
    >
    >
    > Dim sNow
    > sNow = Now
    >
    > Select Case True
    > Case DateValue(sNow) > DateValue("2/2/2004 12:30:00 AM")
    > Response.Redirect "votingover.asp"
    > Case Else
    > Response.Write "fine"
    > m=0
    > End Select
    >
    > Ray at home
    >
    > "Dave" <> wrote in message
    > news:%...
    >> I am getting a syntax error on
    >>
    >> Select Case Now
    >> Case > "2/2/2004 12:30:00 AM"
    >> response.redirect "votingover.asp"
    >> case else
    >> m=0
    >> End Select
     
    Bob Barrows, Jan 29, 2004
    #4
  5. Dave

    Ray at Guest

    OP: "I am getting a syntax error on..."

    ;]

    Ray at home

    "Bob Barrows" <> wrote in message
    news:uyAZd%...
    > Oops. The error message mislead me. Now if he had told us that the error
    > message was "syntax error", ...
    >
    > Of course, this works as well (I tested it this time :) ):
    > Select Case True
    > Case Now > #1/2/2004 12:30:00 AM#
    >
    > Bob Barrows
    > --
    > Microsoft MVP - ASP/ASP.NET
    > Please reply to the newsgroup. This email account is my spam trap so I
    > don't check it very often. If you must reply off-line, then remove the
    > "NO SPAM"
    >
    > Ray at <%=sLocation%> wrote:
    > > The select case statement in vbscript isn't as versatile as that in
    > > VB. Try this:
    > >
    > >
    > > Dim sNow
    > > sNow = Now
    > >
    > > Select Case True
    > > Case DateValue(sNow) > DateValue("2/2/2004 12:30:00 AM")
    > > Response.Redirect "votingover.asp"
    > > Case Else
    > > Response.Write "fine"
    > > m=0
    > > End Select
    > >
    > > Ray at home
    > >
    > > "Dave" <> wrote in message
    > > news:%...
    > >> I am getting a syntax error on
    > >>
    > >> Select Case Now
    > >> Case > "2/2/2004 12:30:00 AM"
    > >> response.redirect "votingover.asp"
    > >> case else
    > >> m=0
    > >> End Select

    >
    >
    >
     
    Ray at, Jan 29, 2004
    #5
  6. Dave

    Bob Barrows Guest

    Ray at <%=sLocation%> wrote:
    > OP: "I am getting a syntax error on..."
    >



    :-(

    Time for a break. I read "type mismatch".

    Maybe my vision was clouded by the comparison of the string to the date ...
    but now that I test it, I see that an implicit conversion is done. This:

    Select Case True
    Case Now > "1/2/2004 12:30:00 AM"

    works just as well as this:
    Select Case True
    Case Now > #1/2/2004 12:30:00 AM#

    Sheesh.

    Bob

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows, Jan 29, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Franks
    Replies:
    2
    Views:
    1,282
    Steve Franks
    Jun 10, 2004
  2. Tee
    Replies:
    3
    Views:
    7,905
    Herfried K. Wagner [MVP]
    Jun 23, 2004
  3. Janice

    lower case to upper case

    Janice, Dec 10, 2004, in forum: C Programming
    Replies:
    17
    Views:
    1,222
    Richard Bos
    Dec 14, 2004
  4. Replies:
    1
    Views:
    2,547
    Mark P
    Apr 6, 2007
  5. darrel

    'case' vs. 'case is'

    darrel, Aug 14, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    295
    Rory Becker
    Aug 14, 2008
Loading...

Share This Page