2016-03-29 146 views
0

使用Crystal Reports版本8,我需要將numbervar轉換爲stringvar。我試過了ToText()(帶有所有大小寫的變體)和CStr()(也帶有各種大小寫),每次CR告訴我「這裏需要一個數字」並將光標移動到我的else塊的開頭。最終試圖將存儲爲NumberVars的小時和分鐘轉換爲字符串,以便我可以顯示「8小時30分」而不是8.50。Crystal Reports將數字轉換爲文本

以下是我對公式至今:

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

問題很簡單......在IFElse你需要返回相同的數據類型,但你在別的塊的起點,因此通過返回和IF通過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"; 
); 
+0

啊,我覺得這很簡單!非常感謝你的幫助! :) –

相關問題