|
-
Jun 5th, 2001, 06:20 AM
#1
Select Case
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!
-
Jun 5th, 2001, 07:42 AM
#2
Frenzied Member
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.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Jun 6th, 2001, 03:20 PM
#3
Addicted Member
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
Things I've Said:
"Life's funny like that...elephants can wear frilly lace panties, and Dubya still looks like a monkey in a big chair"
"Take four goats and strap one to each foot of a llama. Presto, goat-powered llama!"
"You want to get me to work more, get me a Coke. No? Then deal with inferior garbage, I'm not coding another line and your clients can go to......thanks, I'd love a Coke right about now!"
-
Jun 6th, 2001, 03:59 PM
#4
Frenzied Member
This this code...
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
Code:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/test/case.asp, line 4, column 7
Case 0 to 5
------^
I'll look into it some more.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Jun 6th, 2001, 04:06 PM
#5
Frenzied Member
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
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Jun 6th, 2001, 05:11 PM
#6
-
Jun 7th, 2001, 07:33 AM
#7
Hyperactive Member
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.
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
%>
Al.
A computer is a tool, not a toy.
-
Jun 7th, 2001, 08:09 AM
#8
Frenzied Member
Yeah, Chenko, its messy. The if/elseif will work better. You could always move on to a better language: JScript, Perl....
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|