使用Crystal Reports版本8,我需要将numbervar转换为stringvar . 我已经尝试过ToText()(带有大写的所有变体)和CStr()(也有不同的大小写),每次CR告诉我“这里需要一个数字”并将光标移动到我的else块的开头 . 最终尝试将存储为NumberVars的小时和分钟转换为字符串,这样我就可以显示“8h 30m”而不是8.50 .
这是我到目前为止的公式:
if {Collect2000Log.LogCode} = "0002" then 0
else
(
NumberVar OldTime := ((DateDiff("n",{@NextTime},{Collect2000Log.LogWhen})/60)*-1);
NumberVar Hours;
NumberVar Minutes;
StringVar strHours;
StringVar strMinutes;
StringVar NewTime;
//Extract the number of hours
Hours := Int(OldTime);
//Get the decimal portion for minutes
Minutes := Remainder(OldTime, 1) * 100;
//Divide the minutes by 60 to increase the number of hours
Hours := Hours + Int(Minutes / 60);
//Get the remainder for the number of minutes left over
Minutes := Remainder(Minutes, 60);
//Convert hours & mins to strings
strHours := ToText(Hours);
strMinutes := ToText(Minutes):
NewTime := strHours & "h " & strMinutes & "m";
);
现在,当我添加这个公式时,CR说“结束了”,“我很难过 . ”我能够绕过那一次,但现在看起来并不那么充满希望 .
任何帮助将非常感激!
1 回答
问题很简单...在
IF
和Else
中你需要返回相同的数据类型,但是你要通过IF
返回一个数字,并通过Else
返回一个字符串,因此错误a Number is required
在else块的开头..所以转换If
的输出如下字符串 .