VBScript does not support ranges or comparators, as it handles values by comparing the original value to a single value or list of values in each case statement. This is unfortunate but there is a way around it.
dcwave's method doesn't work because the syntax isn't supported. I think bhuning was doing an SQL-based SELECT case which is a differant syntax then VBScript. Drex's will loook like it is working, but it won't be (not really).
in fact, Drex's might be a good example. Since ASP is comparing strictly value to value (unlike VB6, etc that can handle ranges or the IS keyword) then what happens is that it evaluates each case argument asa single value. In Drex's we have:
Select case blah
case 1<=number and number<=5
etc
When VBScript goes to start making comparisons it looks at that case argument and asks if blah is = to (1<=number and number<=5). What happens is the case part gets evaluated down to a boolean value, so you are then comparing your variable to a boolean value. Here's a simple one you can paste andrun yourself:
Code:
Dim a
a = 4
Select Case a
Case a >= 0 And a < 3
response.Write "0-3"
Case a >= 3 and a < 5
Response.Write "3-5"
Case a >= 5 and a < 7
Response.Write "5-7"
Case Else
Response.Write "Out of bounds!"
End Select
At first glance you would think the "3-5" would be hit, but if we evaluate all the argumebnts down to single values (like VBScript would) we'll see why it would hit the Else here everytime:
Code:
Code Becomes:
Dim a
a = 4
Select Case a
Case False
response.Write "0-3"
Case True
Response.Write "3-5"
Case False
Response.Write "5-7"
Case Else
Response.Write "Out of bounds!"
End Select
a won't match false or true, so it ends up being kicked to the else statement.
Solution: A hack I came upo with sometime back that hasn't shown up recently is to Select case on True, but continue to have your expressions in the case statement. This way you can still do comparitive ranges but your not forced to the Else every tme:
Code:
Dim a
a = 4
Select Case [highlight]True[/highlight]
Case a >= 0 And a < 3
response.Write "0-3"
Case a >= 3 and a < 5
Response.Write "3-5"
Case a >= 5 and a < 7
Response.Write "5-7"
Case Else
Response.Write "Out of bounds!"
End Select
Now the first statement that evaluates to true is going to match the original value in your Select case and everything will be good. So instead of having to tpe all the possible values next to your Case you can actually use ranges, since your trying to match boolean to boolean rather then number to boolean.
-T