Click to See Complete Forum and Search --> : Select Case
chenko
Jun 5th, 2001, 06:20 AM
Is there an Easy way to do this in ASP? Ive tried but I get a "Expected statement " error
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!
CiberTHuG
Jun 5th, 2001, 07:42 AM
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.
csammis
Jun 6th, 2001, 03:20 PM
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
CiberTHuG
Jun 6th, 2001, 03:59 PM
This this code...
<%
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 get this error
Microsoft VBScript compilation (0x800A0400)
Expected statement
/test/case.asp, line 4, column 7
Case 0 to 5
------^
I'll look into it some more.
CiberTHuG
Jun 6th, 2001, 04:06 PM
In the meantime...
if (x > 0 and x < 6) then
'do something
elseif(x > 5 and x < 11) then
'do something
else
'do something
end if
harsoni
Jun 6th, 2001, 05:11 PM
even i had the same problem then finally we used IF statements..
Sonia::eek:
Al Smith
Jun 7th, 2001, 07:33 AM
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.
<%
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
%>
Al.
CiberTHuG
Jun 7th, 2001, 08:09 AM
Yeah, Chenko, its messy. The if/elseif will work better. You could always move on to a better language: JScript, Perl....
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.