Is there an Easy way to do this in ASP? Ive tried but I get a "Expected statement " error
Code:Select Case iNumber
Case 0 to 5
Case 6 to 10
Case 11 to 20
Case 21 to 40
Case 41 to 70
Case 71 to 99
Case > 99
Case Else
End Select
Cheers!
Printable View
Is there an Easy way to do this in ASP? Ive tried but I get a "Expected statement " error
Code:Select Case iNumber
Case 0 to 5
Case 6 to 10
Case 11 to 20
Case 21 to 40
Case 41 to 70
Case 71 to 99
Case > 99
Case Else
End Select
Cheers!
Well, you could do this with a series of if/elsif, but to do it with a select switch...
First off, I assume you are using VBScript. Mind you ASP is not a language, it is a server-side technology. You could use JScript (among many others). I would suggest looking into JScript to see if the switch structure is more flexible.
In VBScript, I would suggest trying Case (> x and < y). It may not work, but I'm sure to won't. To implies that it is going to step through a series, as in a for loop.
Anyway, these aren't the answers, just a step toward finding them.
CiberTHuG, are you sure about "X To Y" not working? It works in regular VB, and if it's VBScript in question, the syntax is pretty much the same for logic structures
This this code...
I get this errorCode:<%
x = 20
Select Case x
Case 0 to 5
Response.Write("0 to 5")
Case 6 to 10
Response.Write("6 to 10")
Case 11 to 20
Response.Write("11 to 20")
Case 21 to 40
Response.Write("21 to 40")
Case 41 to 70
Response.Write("41 to 70")
Case > 71
Response.Write("> 71")
Case Else
Response.Write("0 to 5")
End Select
%>
I'll look into it some more.Code:Microsoft VBScript compilation (0x800A0400)
Expected statement
/test/case.asp, line 4, column 7
Case 0 to 5
------^
In the meantime...
Code:if (x > 0 and x < 6) then
'do something
elseif(x > 5 and x < 11) then
'do something
else
'do something
end if
even i had the same problem then finally we used IF statements..
Sonia::eek:
Hi,
It's the to statement that ASP doesn't like.
The following does work but it might be rather cumbersome if your case statements have a large range.
Al.Code:<%
x = 20
Select Case x
Case 0,1,2,3,4,5
Response.Write("0 to 5")
Case 6,7,8,9,10
Response.Write("6 to 10")
Case 11,12,13,14,15,16,17,18,19,20
Response.Write("11 to 20")
Case 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40
Response.Write("21 to 40")
'Case 41 to 70
' Response.Write("41 to 70")
'Case > 71
' Response.Write("> 71")
'Case Else
' Response.Write("0 to 5")
End Select
%>
Yeah, Chenko, its messy. The if/elseif will work better. You could always move on to a better language: JScript, Perl....