【问题标题】:VBScript calculations - VBscript error - when a data field is NULL or 0VBScript 计算 - VBscript 错误 - 当数据字段为 NULL 或 0 时
【发布时间】:2015-03-19 17:16:04
【问题描述】:

这是我遇到问题的一段代码。

<%=total+((rs("fee_overall")/100)*rs("fee_wip")-rs("fee_rendered"))%>

如果任何数据字段为 0 或 NULL 则我会收到不匹配错误

"Microsoft VBScript 运行时错误'800a000d' 类型不匹配:'[string:""]'"

感谢任何帮助。

谢谢

【问题讨论】:

  • 您能否提供更多信息,您的代码应该做什么,没有您的完整代码和详细说明,没人能猜出您的问题,stackoverflow.com/help/how-to-ask
  • 它在 ASP 中......计算使用的是 sql 上的数据字段。
  • 如果字段为 null 或 0,则它会失败,但是如果说 - fee_overall = 200,fee_wip = 50,fee_rendered = 25,那么我得到 75,这是正确的......

标签: vbscript asp-classic


【解决方案1】:

在这种情况下 似乎没问题,因为你没有被零除。对于 null 变量,标准解决方案是检查变量是否不为 null ,然后进行计算:

    if not(isnull(rs("feeoveral")) or isnull( rs("fee_wip")) or isnull(rs("fee_rendered")) ) then
    response.write total+((rs("fee_overall")/100)*rs("fee_wip")-rs("fee_rendered"))
    else
    response.write "bolb"
    end if

【讨论】:

  • (a) Null + 0 = Null (b) Null Null throws Invalid use of Null (c) IsNull() 是测试 Null 的方法 - 在发布之前测试您的代码。
【解决方案2】:

这样试试吧。

    Dim fee_over

    If (IsNull(rs("fee_overall"))) Then
    fee_over = "0"
    Else
    fee_over = (rs("fee_overall"))
    End If
response.write total+((Cint(fee_over))/100)

另外请检查您的数据库记录是否为 INT 且默认为 0

【讨论】:

  • 请重新考虑您的fee_over = "0"。您希望通过使用字符串(“0”)而不是数字来实现什么?
  • 因为他的不匹配似乎他已经将他的列设置为 varchar。但你是对的。它应该被赋予 = 0
  • 好的 - 我将字段值更改为 INT(原为 nvarchar),但现在我明白了 - Microsoft VBScript 运行时错误 '800a000b' 除以零 /LRW/Result_Fee_page.asp,第 151 行
  • 第 151 行是 - &lt;td style="width: 156px"&gt;&lt;%=FormatNumber(total+((1-(rs("Job_Costs")/((rs("fee_Overall_2")/100)*rs("fee_WIP"))))*100),0)%&gt;%&lt;/td&gt;
猜你喜欢
  • 1970-01-01
  • 2011-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多