【问题标题】:Classic ASP: Illogical If Statement Result经典 ASP:不合逻辑的 If 语句结果
【发布时间】:2015-10-16 22:29:46
【问题描述】:
response.Write("CurPage=" & CurPage & "<br />")
response.Write("iNumPages=" & iNumPages)
if CurPage < iNumPages then
    response.Write("in correct part")
    writepagebar = sStr & sLink & CurPage + 1 & """ rel=""next"">" _
      & snext & "</a> " & sLink & iNumPages & """><span class=""pagebarquo""" _
      & " style=""font-family:Verdana;font-weight:bold"">&raquo;</span></a>"
else
    response.Write("in bad part")
    writepagebar = sStr & " " & snext & " <span class=""pagebarquo""" _
       & " style=""font-family:Verdana;font-weight:bold"">&raquo;</span>"
end if

这里有什么问题?打印出来了

当前页面=11
iNumPages=52

所以它应该进入正确的部分......但它进入了坏的部分。

我正在尝试将 下一个 字设为超链接...

【问题讨论】:

  • 可能CurPage 正在评估为String。在 VBScript 中"11" &lt; 52 表达式返回False。尝试用if CLng(CurPage) &lt; CLng(iNumPages) then 替换您的条件并观察。不要忘记使用 CDbl、CLng 和 CInt 等将数值变量转换为适当的类型。

标签: if-statement asp-classic logic


【解决方案1】:

可能CurPage 正在评估为String。 由于在 VBScript 中可能有 False 表达式的返回值,如 "11" &lt; 52,因此在比较数值变量之前,您应该确保它的数据类型也是数值,而不是字符串。
这将按您的预期工作。

if CLng(CurPage) < CLng(iNumPages) then
    'correct part
else
    'bad part
end if

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多