“案例1至5”在选择案例中,给出错误!!为什么? [英] "Case 1 To 5" in Select case, giving Error!!. Why?

查看:41
本文介绍了“案例1至5”在选择案例中,给出错误!!为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,


使用关键字To在选择案例中给出错误。以下代码来自 www.microsrosoft。

。 com
本身。这有什么问题?


<%

Dim Number1

Number1 = 7''初始化变量。

选择案例编号1''评估编号1。

案例1到5''1号和5号之间的数字1,包括在内。

Response.Write(" ; 1到5之间)
''以下是唯一一个评估为True的Case子句。

案例6,7,8''Number1介于6和8之间。

Response.Write("介于6和8之间)

案例9到10''Number1是9或10.

回复.Write(大于8)

Case Else''其他值。

Response.Write(不在1和10之间)

结束选择

%>


提前预付

Laks.R

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

推荐答案

Lakshmi Narayanan.R写道:
Lakshmi Narayanan.R wrote:
嗨专家,

使用关键字To在选择案例中给出错误。以下代码来自 www.microsrosoft.com 本身。这有什么不对?


您获得的代码是为VB / VBA编写的。 vbscript不是VB。 vbscript不支持To

关键字。

<%
Dim Number1
Number1 = 7''初始化变量。
选择案例编号1''评估编号1。
案例1到5''1号和5号之间的数字1,包括在内。
Response.Write("介于1和5之间)
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" )




这应该是:

Response.Write"介于1和5之间


仅在VB / VBA /中使用括号调用函数时的vbscript,它返回你正在消耗的
值。如果您在不消耗返回值的情况下调用具有多个

参数的方法,则使用括号会导致

出错。


通过消费返回值我的意思是:


1.将返回值设置为变量:

设置a = createobject(" some.class")

括号是必需的


2.评估返回值:

功能测试(x,y)

如果x> ;然后

test = true

else

test = false

结束如果

end函数

如果测试(10,5)则...


再次,需要括号。


调用测试而不消耗返回值需要将其称为

,如Sub(没有括号):


test 10,5


除非使用Call语句:

通话测试(10,5)


更多信息:
http://weblogs.asp.net/ ericlippert / a ... / 15 / 52996.aspx

HTH,

Bob Barrows

-

Microsoft MVP - ASP / ASP.NET

请回复新闻组。这个电子邮件帐户是我的垃圾邮件陷阱所以我

不经常检查它。如果您必须离线回复,请删除

NO SPAM



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"


Bob Barrows [MVP]于2005年2月2日在

microsoft.public.inetserver.asp.general:
Bob Barrows [MVP] wrote on 02 mrt 2005 in
microsoft.public.inetserver.asp.general:
2.评估返回值:
功能测试(x,y)
如果x> ; y然后
test = true
否则
test = false
结束如果
结束功能
2. Evaluating the return value:
Function test(x,y)
if x>y then
test=true
else
test=false
end if
end Function




为什么不简单:


功能测试(x,y)

test = x> y

结束功能

-

Evertjan。

荷兰。

(用我的电子邮件地址替换所有带点的十字架)



Why not simply:

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


Evertjan。写道:
Evertjan. wrote:
Bob Barrows [MVP]于2005年2月2日在
microsoft.public.inetserver.asp.general写道:
Bob Barrows [MVP] wrote on 02 mrt 2005 in
microsoft.public.inetserver.asp.general:
2.评估返回值:
功能测试(x,y)
如果x> y然后
test = true
否则
test = false
结束如果
结束功能
2. Evaluating the return value:
Function test(x,y)
if x>y then
test=true
else
test=false
end if
end Function



为什么不简单:

功能测试(x,y)
test = x> y
end函数



2个理由:

清晰度 - 虽然你的效率更高,但我的新手更清楚。如果我自己写的是
,我会使用你的版本。


真正的原因:我最初写了一个不同的例子,当我改变了/>
对此,我太懒了,不能用更高效的版本重写它。

:-)


Bob Barrows


-

Microsoft MVP - ASP / ASP.NET

请回复新闻组。我的From

标题中列出的电子邮件帐户是我的垃圾邮件陷阱,因此我不经常检查它。通过发布到新闻组,您将获得更快的回复。


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.


这篇关于“案例1至5”在选择案例中,给出错误!!为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆