Crystal 报告将数字转换为文本

Crystal Reports convert number to text

使用 Crystal 报告版本 8,我需要将 numbervar 转换为 stringvar。我已经尝试了 ToText() (各种大写形式)和 CStr() (也有各种大写形式),每次 CR 告诉我 "A number is required here" 并将光标移动到我的 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 显示 "The end ) is missing",我很困惑。我曾经能够绕过那个,但现在看起来没那么有希望了。

如有任何帮助,我们将不胜感激!

问题很简单...在 IFElse 中,您需要 return 相同的数据类型,但您 return 通过 IF 和一个通过 Else 的字符串,因此在 else 块的开头出现错误 a Number is required。因此将 If 的输出转换为如下所示的字符串。

if {Collect2000Log.LogCode} = "0002" 
then ToText(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";
);