473,657 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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 7372
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("s ome.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.publi c.inetserver.as p.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.publi c.inetserver.as p.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("s ome.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******** ********@TK2MSF TNGP10.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
14626
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 allow entry to one or the other or Both at the same time. Now I tried to use an If ElseIf but it got too hard to track, so now I am using a SELECT CASE Statement.
9
3624
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 doing wrong? Thanks
8
3765
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. *************************** intWeightTotal = 550 Select Case intWeightTotal
3
3765
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 a word or a number, ie... Low or 1 Medium or 2 High or 3
25
4327
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 Response.Write "Test2" Case Is > 0 <<< Syntax Error Response.Write "Test3" End Select
2
5170
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. -------------------------------------------------------- SELECT b.ISBN, b.Title, b.SmallImage, f.idForSale, count(f.idForSale) FROM books b, forsale f
3
7454
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 ,( SELECT A.I_PO FROM P.PQDCLSA A WHERE A.I_INCDNT = B.I_INCDNT ) I_PO FROM P.PQDCLSM B WHERE B.I_INCDNT = '0700100';
4
10933
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 to keyword "To") Is there anyone know if ASP support the keyword "To"? or it use another keyword to have the case condition in range? I know I can use a comma to form a multi condition, like "Case 164, 165, 166, 167", etc. However, I need a range...
3
2331
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 select case where it's giving me " Case without Select case" here is the offfending code. Private Sub loginbutton_Click() Dim rs As Recordset Dim db As Database Set db = CurrentDb Dim searchstr As String 'If Not DLookup("Password", "Security",...
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7352
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.