预期语句结束 If [英] Expected Statement End If

查看:26
本文介绍了预期语句结束 If的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单中设置了以下代码,但出现预期语句"错误.我第一次这样做,并认为我的语法是正确的,我错过了什么?

I have the following code setup in a form and I'm getting the "Expected Statement" error. My first time doing this and thought I had the syntax correct, what am I missing?

            <%
            If Trim(oQuote("shipmeth"))="FREIGHT" Then 
                Response.Write "Freight" 
            ElseIf Trim(oQuote("shipmeth"))="THRSHLD" Then 
                Response.Write "Threshold"
            End If
            %>

推荐答案

当使用嵌套的 2-way 条件时,每个条件必须由自己的 End If 关闭:

When using nested 2-way conditionals, each conditional must be closed by its own End If:

If condition_A Then
  action_A
Else
  If condition_B Then
    action_B
  Else
    If condition_C Then
      action_C
    Else
      action_D
    End If 'condition_C
  End If 'condition_B
End If 'condition_A

只有一个 n-way 条件可以用单个 End If 关闭(因为它只是一个条件):

Only an n-way conditional can be closed with a single End If (because it's just a single conditional):

If condition_A Then
  action_A
ElseIf condition_B Then
  action_B
ElseIf condition_C Then
  action_C
Else
  action_D
End If

但是,这种 n-way 条件仅在您检查不同条件时才有意义,例如

However, this kind of n-way conditional only makes sense when you're checking different conditions, e.g.

If IsEmpty(a) Then
  ...
ElseIf b > 23 Then
  ...

在检查同一变量的不同值时,最好使用 Select 语句作为 Alex K. 建议:

When checking the same variable for different values it's better to use a Select statement as Alex K. suggested:

Select Case foo
  Case "a"
    'handle foo="a"
  Case "b", "d"
    'handle foo="b" as well as foo="d"
  Case Else
    'handle non-matches
End Select

这篇关于预期语句结束 If的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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