注册 登录
编程论坛 ASP技术论坛

还是老问题,if 与ENDIF配对

sylknb 发布于 2010-03-17 18:46, 1474 次点击
我摘于书上:还是不太懂!!兰色的配对根据题目意思好象能配上,就是红色的 <% End If %>它到底于誰配对。因VB中有时可省ENDIF。有三个问题,请指教。

<% If Rs("User") = Session("User") Or Rs("IsView") = 0 Then %>
         
                 (1) <% If Rs("User") = Session("User") Then %>此句好象没有<%endif%>了
         
                       (2) <% If Rs("IsView")=1 Then Response.Write "隐藏" Else Response.Write "不隐%>         
                <a href="edit_myinfo.asp">我要修改</a> 这句是不是与上面ELSE 有关还是与(1)有关?
                           
                <% End If %>    这个<% endif%> 与  (1)配对还是与(2)配对          
            <% Else %>
<td height="30" align="center" colspan="2">Sorry!该会员已设</td></tr>        
            <% End If %>
4 回复
#2
yms1232010-03-18 08:54
你把代码缩进和格式控制好了,自然就能找到那个end if没配对。
一般在vbscript中不需要配对的就是if在一行时
if xxx then xxx
一行不需要end if
两行时
if xxx then
   xxx
end if
必须加
#3
zhangyxsd2010-03-18 09:09
<% If Rs("User") = Session("User") Or Rs("IsView") = 0 Then %>
         
                 (1) <% If Rs("User") = Session("User") Then %>         
                       (2) <% If Rs("IsView")=1 Then Response.Write "隐藏" Else Response.Write "不隐%>         
                <a href="edit_myinfo.asp">我要修改</a> 这句是不是与上面ELSE 有关还是与(1)有关?
                           
                <% End If %>    这个<% endif%> 与  (1)配对(2)在一行上不需要END IF 的 ?           
            <% Else %>
<td height="30" align="center" colspan="2">Sorry!该会员已设</td></tr>        
            <% End If %>


这个很好分辨的,asp 中if 的用法这样的
如果 if ????? then ?????   那么就不需要end if(在一行上不需要end if)
if ???? then ??? else ?????  这个与上面同理的。
如果  
if ???? then
?????
end if
这个就需要end if因为then 后面的代码另起一行了。

if ????? then
????
elseif ????? then
????
end if
这个与上面的同理另起一行了。
通常在多个if else, end if的代码里是就近搭配的,即if else与离得最近的end if是一对的。
回答完毕。
请看看我做的网站  

http://www.
#4
aspic2010-03-18 09:12
最重要的是缩进 不然自己看着麻烦别人看着也麻烦
#5
sylknb2010-03-18 19:08
多谢zhangyxsd三楼了,讲得太合心了。你讲的if ???? then ??? else ?????  这个与上面同理的。这一句我总算也找到了解答。一般书上只讲if ????? then ?????   那么就不需要end if(在一行上不需要end if)

1