Case statement

D

Dave

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
 
B

Bob Barrows

Dave said:
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
 
R

Ray at

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
 
B

Bob Barrows

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
 
B

Bob Barrows

Ray at said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top