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
%>

怎么是错的,帮忙改正。给分。
...全文
126 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
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)

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧