if... else if .....else if的语句怎么写? 跪求

wjohen 2004-04-01 08:36:31
<%@ LANGUAGE=VBScript CodePage = 936%>
<%
function getProvince(iProvince)

if iprovince=17 then
getProvince="北京"
else
getProvince="上海"
end if
end function
%>

怎么是错的,帮忙改正。给分。
...全文
70 点赞 收藏 16
写回复
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
stefli 2004-04-01
getPro = "全网"
这里有点错误哦。 需要用
if ipro<>0 and .... then getPro = "全网"

所以,对于这种情况,最好使用select case ipro
回复
stefli 2004-04-01
使用下面的代码,其实你的注意if的用法
如果
if statement then expression
那么就没有else了,如果
if statement then
expression
else
expression
end if
也就看是否then 后面直接跟表达式


-------------------------------------------
[CODE]
-------------------------------------------
<%@ LANGUAGE=VBScript CodePage = 936%>
<%
Function getPro( ipro )
if ipro = 0 then getPro = "广东"
if ipro = 13 then getPro = "福建"
if ipro = 3 then getPro = "河北"
if ipro = 8 then getPro = "黑龙江"
if ipro = 16 then getPro = "河南"
if ipro = 17 then getPro = "湖北"
if ipro = 18 then getPro = "湖南"
if ipro = 19 then getPro = "广东"
if ipro = 10 then getPro = "江苏"
if ipro = 6 then getPro = "辽宁"
if ipro = 26 then getPro = "陕西"
if ipro = 23 then getPro = "四川"
if ipro = 2 then getPro = "天津"
if ipro = 11 then getPro = "浙江"
if ipro = 7 then getPro = "吉林"
if ipro = 22 then getPro = "重庆"
if ipro = 25 then getPro = "云南"
getPro = "全网"
END FUNCTION
%>
回复
liuyu202 2004-04-01
建议不要这么写代码elseif ipro = 25 then getPro = "云南",
要这样写elseif ipro = 25 then
getPro = "云南"

写成一行,容易出错!
回复
eyun 2004-04-01
你用缩进的方法容易看出,其实 else 后面的if是和后面大then,else end if是连在一起的.是上一个if的子句

<%
if asd then
asdfasdfasdf
else
if fasdfasdf then
asdfasdfasd
else
if adsfadfasdft then
asdfasdfasdf
end if
end if
end if
%>
回复
wjohen 2004-04-01
我把
elseif ipro = 25 then getPro = "云南"
写成
elseif ipro = 25 then
getPro = "云南"
就好了。

不知道为什么?

回复
pizixt 2004-04-01
if then elseif 语句要换行

if ipro = 0 then
getPro = "广东"
elseif ipro = 13 then
getPro = "福建"
....
回复
liuyu202 2004-04-01
这样写就没错了!
Function getPro( ipro )
if ipro = 0 then
getPro = "广东"
elseif ipro = 13 then
getPro = "福建"
elseif ipro = 3 then
getPro = "河北"
elseif ipro = 8 then getPro = "黑龙江"
elseif ipro = 16 then getPro = "河南"
elseif ipro = 17 then getPro = "湖北"
elseif ipro = 18 then getPro = "湖南"
elseif ipro = 19 then getPro = "广东"
elseif ipro = 10 then getPro = "江苏"
elseif ipro = 6 then getPro = "辽宁"
elseif ipro = 26 then getPro = "陕西"
elseif ipro = 23 then getPro = "四川"
elseif ipro = 2 then getPro = "天津"
elseif ipro = 11 then getPro = "浙江"
elseif ipro = 7 then getPro = "吉林"
elseif ipro = 22 then getPro = "重庆"
elseif ipro = 25 then getPro = "云南"
else
getPro = "全网"
end if
END FUNCTION
回复
guokai1217 2004-04-01
不是你的函数当中少了,估计是你上边的代码少了。有时候,提示的错误不是你真正出逻辑错误的地方.
你代码要不是很长的话,建议你对照着一个个分析一下你的IF语句有没有问题.
回复
pizixt 2004-04-01
<%
Function getPro(ipro)
select case ipro
case 0
getPro = "广东"
case 2
getPro = "天津"
case 3
getPro = "河北"
case 6
getPro = "辽宁"
case 7
getPro = "吉林"
case 8
getPro = "黑龙江"
case 10
getPro = "江苏"
case 11
getPro = "浙江"
case 13
getPro = "福建"
case 16
getPro = "河南"
case 17
getPro = "湖北"
case 18
getPro = "湖南"
case 19
getPro = "广东"
case 22
getPro = "重庆"
case 23
getPro = "四川"
case 25
getPro = "云南"
case 26
getPro = "陕西"
case else
getPro = "全网"
end select
END FUNCTION

response.write getPro(17)
%>
回复
wjohen 2004-04-01
为什么老是说我少了end呢
回复
wjohen 2004-04-01
我下面的哪里错了
<%@ LANGUAGE=VBScript CodePage = 936%>
<%
Function getPro( ipro )
if ipro = 0 then getPro = "广东"
elseif ipro = 13 then getPro = "福建"
elseif ipro = 3 then getPro = "河北"
elseif ipro = 8 then getPro = "黑龙江"
elseif ipro = 16 then getPro = "河南"
elseif ipro = 17 then getPro = "湖北"
elseif ipro = 18 then getPro = "湖南"
elseif ipro = 19 then getPro = "广东"
elseif ipro = 10 then getPro = "江苏"
elseif ipro = 6 then getPro = "辽宁"
elseif ipro = 26 then getPro = "陕西"
elseif ipro = 23 then getPro = "四川"
elseif ipro = 2 then getPro = "天津"
elseif ipro = 11 then getPro = "浙江"
elseif ipro = 7 then getPro = "吉林"
elseif ipro = 22 then getPro = "重庆"
elseif ipro = 25 then getPro = "云南"
else
getPro = "全网"
end if
END FUNCTION
%>
回复
cxty 2004-04-01
为什么不用
select case
回复
pizixt 2004-04-01
response.write getProvince(17) '北京
response.write getProvince(99) '上海

正确,无错误
回复
wjohen 2004-04-01
<%@ LANGUAGE=VBScript CodePage = 936%>
<%
Function getPro( ipro )
if ipro = 0 then getPro = "广东"
elseif ipro = 13 then getPro = "福建"
elseif ipro = 3 then getPro = "河北"
elseif ipro = 8 then getPro = "黑龙江"
elseif ipro = 16 then getPro = "河南"
elseif ipro = 17 then getPro = "湖北"
elseif ipro = 18 then getPro = "湖南"
elseif ipro = 19 then getPro = "广东"
elseif ipro = 10 then getPro = "江苏"
elseif ipro = 6 then getPro = "辽宁"
elseif ipro = 26 then getPro = "陕西"
elseif ipro = 23 then getPro = "四川"
elseif ipro = 2 then getPro = "天津"
elseif ipro = 11 then getPro = "浙江"
elseif ipro = 7 then getPro = "吉林"
elseif ipro = 22 then getPro = "重庆"
elseif ipro = 25 then getPro = "云南"
else
getPro = "全网"
end if
END FUNCTION
%>
回复
wjohen 2004-04-01
它报出错误少了 end
回复
stefli 2004-04-01
function getProvince(iProvince)

if iProvince=17 then
'-----^
getProvince="北京"
else
getProvince="上海"
end if
end function
语句没有什么错误啊。
那的看看你的iProvince是否正确了。
response.write cInt(iProvince)
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告