473,322 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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
10 7342
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
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
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
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
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
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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Newbie | last post by:
Dear friends, I am having a hard time understanding how to use a SELECT CASE in ASP. I have used it in VB but never in ASP scripting. Scenerio: I have 2 textboxes on a form that I have to...
9
by: Kevin | last post by:
Hi, I am getting a syntax error Microsoft VBScript compilation error '800a03ea' Syntax error On the code below. The error references the "End Select" line Can anyone help me with what I am...
8
by: Penny | last post by:
Hi all, My browser throws this Select Case block back at me pointing out a syntax error on the line: 'Case < 251', between the word 'Case' and the '<' symbol. *************************** ...
3
by: Rob Meade | last post by:
Ok - I *think* this is only different in .net 2.0 - as I've not had any problems in the past, but then maybe I've not tried it... I have a value being read from an xml file where the value maybe...
25
by: CJM | last post by:
I'm getting a syntax error with a Select Case statement: Select Case CSng(rs.fields("Field1")) Case 0 Response.Write "Test1" Case Is < 0 <<< Syntax Error...
2
by: scole954387 | last post by:
Hi, I have a problem. I have written a SQL statement that has a nested select case statement on the 'where' clause to condition the results. ...
3
by: ashishg77 | last post by:
Hi I have some business requirement for which i need to format some query which will be something like this SELECT B.D_INCDNT ,B.L_INCDNT_TYP ...
4
by: makinha | last post by:
Hello, I am getting a syntax error Microsoft VBScript compilation error '800a0400' Expected statement line 49 Case 164 To 269 ---------------^ (The error references...
3
by: lee weaver | last post by:
I have an odd situtation where a section of code is resetting the status of either multi line If statments which then gives me the error " end if without block if" or something very similure, or ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.