公式中没有错误,但是当我到达某个页面时,我收到"String is non-numeric"错误,并且无法再预览报告



我对编程相当陌生,目前正在自学Crystal Reports…

我有一个没有错误的公式,但是当我到达报告中的某一页时,它给我一条消息说"这个字符串是非数字的"。

这是公式,任何帮助都是非常感激的!
select {@Upright/Grand}
case "Grand" : if tonumber({scsub.sub_desc}[1]) < 6 then 'Under 6' & chr(146)
else
if tonumber({scsub.sub_desc}[1]) = 6 then '6' & chr(146) & chr(150) & '7' & chr(146)
else
if tonumber({scsub.sub_desc}[1]) > 6 then '7' & chr(146) & chr(43) 
default : if tonumber({sccat.cat_desc} [1]) <= 42 then '44' & chr(34) & ' and Under' 
else
if tonumber({sccat.cat_desc} [1])  in 45 _to_ 48 then '45' & chr(34) & chr(150) & '48' & chr(34)
else
if tonumber({sccat.cat_desc} [1])  in 49 to 52 then '49' & chr(34) & chr(150) & '52' & chr(34)

问题是tonumber函数,您正在尝试将非数值转换为数字…因此出现此错误。

你有两个选择:

  1. 首先使用IsNumeric测试字段是否为数字,如果结果为真,则继续进行计算。像这样

     if IsNumeric({scsub.sub_desc}[1]) 
     then //your code
    
  2. 不要将字段转换为数值,而是将比较值转换为字符串,这将更有用,更不容易出错。大概是这样的。

     if {scsub.sub_desc}[1] < ToText(6) then 'Under 6' & chr(146)
    

您应该首先添加一个'else'值,以防所有的'if'情况都没有得到验证。然后,您应该确保{sccat。Cat_desc}[1]只返回可以转换为数字的字符串值:没有空,没有空字符串,没有空格,没有字符,没有什么:只有普通的数字。

相关内容

最新更新