By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,017 Members | 1,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,017 IT Pros & Developers. It's quick & easy.

"Case 1 To 5" in Select case, giving Error!!. Why?

P: n/a
Hi Experts,

Using keyword "To" in select case giving error.The following code is got
from www.microsrosoft.com itself. What is the wrong with this?.

<%
Dim Number1
Number1 = 7 ' Initialize variable.
Select Case Number1 ' Evaluate Number1.
Case 1 To 5 ' Number1 between 1 and 5, inclusive.
Response.Write( "Between 1 and 5" )
' The following is the only Case clause that evaluates to True.
Case 6, 7, 8 ' Number1 between 6 and 8.
Response.Write( "Between 6 and 8")
Case 9 To 10 ' Number1 is 9 or 10.
Response.Write( "Greater than 8")
Case Else ' Other values.
Response.Write( "Not between 1 and 10")
End Select
%>

Thanx in advance
Laks.R
Jul 22 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Lakshmi Narayanan.R wrote:
Hi Experts,

Using keyword "To" in select case giving error.The following code is
got from www.microsrosoft.com itself. What is the wrong with this?.
The code you you got was written for VB/VBA. vbscript is not VB. The To
keyword is not supported in vbscript.

<%
Dim Number1
Number1 = 7 ' Initialize variable.
Select Case Number1 ' Evaluate Number1.
Case 1 To 5 ' Number1 between 1 and 5, inclusive.
Response.Write( "Between 1 and 5" )


This should be:
Response.Write "Between 1 and 5"

Only use parentheses in VB/VBA/vbscript when calling a function whose return
value you are consuming. If you were calling a method with more than one
argument without consuming the return value, using parentheses would raise
an error.

By "consuming the return value" I mean:

1. Setting the return value to a variable:
Set a = createobject("some.class")
Parentheses are required

2. Evaluating the return value:
Function test(x,y)
if x>y then
test=true
else
test=false
end if
end Function
if test(10,5) then ...

Again, parentheses are required.

Calling test without consuming the return value requires that it be called
like a Sub (with no parentheses):

test 10, 5

unless using the Call statement:
Call test(10,5)

More here:
http://weblogs.asp.net/ericlippert/a.../15/52996.aspx
HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #2

P: n/a
Bob Barrows [MVP] wrote on 02 mrt 2005 in
microsoft.public.inetserver.asp.general:
2. Evaluating the return value:
Function test(x,y)
if x>y then
test=true
else
test=false
end if
end Function


Why not simply:

Function test(x,y)
test = x>y
end Function
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #3

P: n/a
Evertjan. wrote:
Bob Barrows [MVP] wrote on 02 mrt 2005 in
microsoft.public.inetserver.asp.general:
2. Evaluating the return value:
Function test(x,y)
if x>y then
test=true
else
test=false
end if
end Function


Why not simply:

Function test(x,y)
test = x>y
end Function

2 reasons:
Clarity - While yours is more efficient, mine is clearer to the newbie. If I
was writing it myself, I would use your version.

The real reason: I originally wrote a different example, and when I changed
it to this, I was too lazy to rewrite it using the more efficient version.
:-)

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #4

P: n/a
Hi MVP's

Did u run the code, i have pasted.

What u said is correct for Functions other than comes in collections.
So, writing Response.Write with paranthesis will work fine.
My question is that the error comes in the line "case 1 to 5".

So pls run the code run the code run the code and find the solution.

Regards
Laks.R

"Bob Barrows [MVP]" wrote:
Lakshmi Narayanan.R wrote:
Hi Experts,

Using keyword "To" in select case giving error.The following code is
got from www.microsrosoft.com itself. What is the wrong with this?.


The code you you got was written for VB/VBA. vbscript is not VB. The To
keyword is not supported in vbscript.

<%
Dim Number1
Number1 = 7 ' Initialize variable.
Select Case Number1 ' Evaluate Number1.
Case 1 To 5 ' Number1 between 1 and 5, inclusive.
Response.Write( "Between 1 and 5" )


This should be:
Response.Write "Between 1 and 5"

Only use parentheses in VB/VBA/vbscript when calling a function whose return
value you are consuming. If you were calling a method with more than one
argument without consuming the return value, using parentheses would raise
an error.

By "consuming the return value" I mean:

1. Setting the return value to a variable:
Set a = createobject("some.class")
Parentheses are required

2. Evaluating the return value:
Function test(x,y)
if x>y then
test=true
else
test=false
end if
end Function
if test(10,5) then ...

Again, parentheses are required.

Calling test without consuming the return value requires that it be called
like a Sub (with no parentheses):

test 10, 5

unless using the Call statement:
Call test(10,5)

More here:
http://weblogs.asp.net/ericlippert/a.../15/52996.aspx
HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 22 '05 #5

P: n/a
Lakshmi Narayanan.R wrote:
Hi MVP's

Did u run the code, i have pasted.

What u said is correct for Functions other than comes in collections.
So, writing Response.Write with paranthesis will work fine.
Of course it works fine (sort of): there's only one argument. That does not
mean it is correct. You are forcing the compiler to do a little extra work.
Granted, you will not notice the extra work it's doing, but there is no
reason to make it do it.
My question is that the error comes in the line "case 1 to 5".
I answered that question. I understand there may be a language difference
between us, but I did answer this.

So pls run the code run the code run the code and find the solution.


There is no need to run it.
There is no solution for this in vbscript. It works in Visual Basic. It does
NOT work in vbscript.
There IS a workaround:

Select Case true
Case (Number1>=1 and Number1 <=5)
...
End Select

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #6

P: n/a
Hi MVP's

Thank u for ur reply.
Removing the paranthesis also giving the same error for the word "TO" in the
case 1 to 5

The error is here

Microsoft VBScript compilation error '800a0400'

Expected statement

/asp/casestat.asp, line 5

Case 1 To 5 ' Number1 between 1 and 5, inclusive.
-------^

So pls take a little effort and reply me.
Thanx for ur suggession

Laks.R

"Bob Barrows [MVP]" wrote:
Lakshmi Narayanan.R wrote:
Hi MVP's

Did u run the code, i have pasted.

What u said is correct for Functions other than comes in collections.
So, writing Response.Write with paranthesis will work fine.


Of course it works fine (sort of): there's only one argument. That does not
mean it is correct. You are forcing the compiler to do a little extra work.
Granted, you will not notice the extra work it's doing, but there is no
reason to make it do it.
My question is that the error comes in the line "case 1 to 5".


I answered that question. I understand there may be a language difference
between us, but I did answer this.

So pls run the code run the code run the code and find the solution.


There is no need to run it.
There is no solution for this in vbscript. It works in Visual Basic. It does
NOT work in vbscript.
There IS a workaround:

Select Case true
Case (Number1>=1 and Number1 <=5)
...
End Select

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 22 '05 #7

P: n/a
Lakshmi Narayanan.R wrote:
Hi MVP's

Thank u for ur reply.
Removing the paranthesis also giving the same error for the word "TO"
The parentheses issue was not related to the "TO" issue. It was a side
issue. I answered your question about "To" with my very first sentences:
The code you you got was written for VB/VBA. vbscript is not VB. The To
keyword is not supported in vbscript.
Then in my second message:
There is no solution for this in vbscript. It works in Visual Basic. It does
NOT work in vbscript.
There IS a workaround:
<snip - go back and read it yourself - it's time YOU made the effort to
understand what I'm saying to you>

For the last time:
The "TO" keyword is NOT LEGAL in the vbscript Case statement.
You can download the vbscript documentation from here:
http://tinyurl.com/7rk6

<snip>
So pls take a little effort and reply me.


I provided a workaround for you in my previous reply. PLEASE READ THE ENTIRE
MESSAGE! This is the second time you have accused me of not making any
effort for you. It will be the last.

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #8

P: n/a
"Bob Barrows [MVP]" wrote in message
news:OJ****************@TK2MSFTNGP10.phx.gbl...
: Lakshmi Narayanan.R wrote:
: > Hi MVP's
: >
: > Thank u for ur reply.
: > Removing the paranthesis also giving the same error for the word "TO"
:
: The parentheses issue was not related to the "TO" issue. It was a side
: issue. I answered your question about "To" with my very first sentences:
:
: >>>
: The code you you got was written for VB/VBA. vbscript is not VB. The To
: keyword is not supported in vbscript.
: >>>
:
: Then in my second message:
:
: >>>
: There is no solution for this in vbscript. It works in Visual Basic. It
does
: NOT work in vbscript.
: There IS a workaround:
: <snip - go back and read it yourself - it's time YOU made the effort to
: understand what I'm saying to you>
: >>>
:
:
: For the last time:
: The "TO" keyword is NOT LEGAL in the vbscript Case statement.
: You can download the vbscript documentation from here:
: http://tinyurl.com/7rk6
:
: <snip>
: >
: > So pls take a little effort and reply me.
:
: I provided a workaround for you in my previous reply. PLEASE READ THE
ENTIRE
: MESSAGE! This is the second time you have accused me of not making any
: effort for you. It will be the last.

You know Bob, I'm so confused now. Could you go over it just one more time
and what about that keyword IS, can I use that instead? (O:=

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp

Jul 22 '05 #9

P: n/a
I beg very very sorry Mr.Bob,

As u said, i didnt read carefully after the first para.Seeing the replyies
in small window, i did the mistake.

Pls dont mistaken me.

Thank u for ur solutions.

Regards
Laks.R

"Bob Barrows [MVP]" wrote:
Lakshmi Narayanan.R wrote:
Hi MVP's

Thank u for ur reply.
Removing the paranthesis also giving the same error for the word "TO"


The parentheses issue was not related to the "TO" issue. It was a side
issue. I answered your question about "To" with my very first sentences:
The code you you got was written for VB/VBA. vbscript is not VB. The To
keyword is not supported in vbscript.
Then in my second message:
There is no solution for this in vbscript. It works in Visual Basic. It does
NOT work in vbscript.
There IS a workaround:
<snip - go back and read it yourself - it's time YOU made the effort to
understand what I'm saying to you>

For the last time:
The "TO" keyword is NOT LEGAL in the vbscript Case statement.
You can download the vbscript documentation from here:
http://tinyurl.com/7rk6

<snip>

So pls take a little effort and reply me.


I provided a workaround for you in my previous reply. PLEASE READ THE ENTIRE
MESSAGE! This is the second time you have accused me of not making any
effort for you. It will be the last.

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 22 '05 #10

P: n/a
Lakshmi Narayanan.R wrote:
I beg very very sorry Mr.Bob,


Apology accepted. Let's move on to the next problem. :-)
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.