Using Crystal Reports version 8 and I need to convert a numbervar to stringvar. I have tried ToText() (with all variations of capitalization) and CStr() (also with various capitalizations) and each time CR tells me "A number is required here" and moves the cursor to the beginning of my else block. Ultimately trying to convert hours and minutes both stored as NumberVars to strings so I can display "8h 30m" instead of 8.50.
Here is what I have for the formula so far:
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";
);
And now when I add this formula CR says "The end ) is missing" and I'm stumped. I was able to get around that once but now not looking so hopeful.
Any help would be much appreciated!
Problem is simple... In an IF and Else you need to return same data type but you are returning a number through IF and a String through Else hence the error a Number is required at the starting of the else block.. so convert the output of If to string like below.
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";
);
Related
How to calculate hours and mins from decimal number using crystal report formula
Hours and mins
42.00
397.00
2.20
63.40
2.36
1.30
0.50
----------------
508.76
----------------
Sum of values 508.76
I want to convert it into 509.16 -> 509 Hours 16 mins
Explanation In the 76 mins -> 60 mins converted to 1 hr so 509 hrs
remaining 16 mins displayed as mins so 509.16
Achieve using this method: 508 + (76/60) = 509, 76%60 = 16
76/60 Quotient 1, it added to integer part 508 + 1 now 509 hrs
76%6 Remainder 16, it will be 16 mins
tried this code for get fraction value
local numbervar sum_hours := sum({Command.TotalHours});
local numbervar fraction;
fraction := sum_hours - truncate(sum_hours);
it gives 0.76, how to get 76
can anyone explain with complete code how to write below expression and get result using crystal report formula
split 508.76 into 508 and 76 and calculate using below method
508 + (76/60) = 509, 76%60 = 16
I think the easiest approach to your problem would be to convert the individual values so the time they represent is expressed in minutes instead of "hours.minutes".
This formula takes a value of 5.38 (5 hours, 38 minutes) and converts it to minutes by splitting the value into a string array using the decimal as a delimiter. It then multiplies the hours by 60 to convert it to minutes, and adds the remaining minutes.
Whileprintingrecords;
Shared NumberVar value:= 5.38;
Shared StringVar array x := split(ToText(value),".");
Shared NumberVar hours := ToNumber(x[1]) * 60;
Shared NumberVar minutes := ToNumber(x[2]);
hours + minutes;
Once you have all of your data converted to minutes, you can easily sum them, then convert it back to hours and minutes with this formula. Replace {#Test} with the fieldname that contains the total value (in minutes) that you want to convert back to "minutes.hours".
WhilePrintingRecords;
ToNumber(ToText(Truncate({#Test}/60),0,"") & "." & ToText({#Test}Mod 60,0,""));
To transform 0.76 to 76, multiply by 100:
local numbervar sum_hours := 508.76; //sum({Command.TotalHours});
local numbervar fraction;
local numbervar hours;
local numbervar minutes;
fraction := sum_hours - truncate(sum_hours);
hours := truncate(sum_hours) + (fraction mod 60);
minutes := remainder(fraction * 100, 60);
ToText(hours,0) + ' hours and ' + ToText(minutes,0) + ' minutes'
I am using Crystal Reports 2013 SP5 on Windows 7 Pro pulling from an Oracle db.
I am trying to write a formula(s) in crystal reports that returns the total number of days the remaining hours if less than 24, and the remaining minutes if less than 60 from a datediff between two date time fields.
So far I have managed to show the total number of minutes as days, hours, and minutes:
local numbervar tm := datediff('n',{table.date1},{table.date2},0);
local numbervar h := truncate(tm/60,0);
local numbervar d := truncate(tm/1440,0);
local stringvar tm_d := totext(d,0,"") + ' days ';
local stringvar tm_h := totext(h,0,"") + ' hours ';
local stringvar tm_m := totext(tm,0,"") + ' minutes ';
local stringvar tm_string := tm_d & tm_h & tm_m
Returns: 183 days 4393 hours 263633 minutes
183 days which is = to 4393 hours which is = to 263633 minutes
What I need it to do is show 183 days (not rounded) and any remaining hours (not rounded) and any remaining minutes (not rounded) so it looks something like this:
The difference between table.date1 and table.date2 is:
183 days 4 hours 23 minutes (just used random hours and minutes)
Just try this also.
local numbervar tt := datediff('n',{table.DATE1},{table.DATE2});
local numbervar d := truncate(tt/1440,0);
local numbervar h := truncate(remainder(tt,1440)/60,0);
local numbervar m := truncate(remainder(tt,60),0);
local stringvar tt_d := if d=0 then "" else totext(d,0,"") + 'd ';
local stringvar tt_h := if h = 0 then "" else (totext(h,0,"")) + 'h ';
local stringvar tt_m := totext(m,0,"") + 'm ';
local stringvar tt_string := tt_d & tt_h & tt_m
Refer links :
http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=15879
http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=10279
http://www.experts-exchange.com/Database/Reporting/Crystal_Reports/Q_24014196.html
Have no experience with your system, but definitely you'll need this:
totalMinutes = 263633
days = floor (totalMinutes /(24*60))
hours = floor (totalMinutes %(24 * 60) /(60))
minutes = floor (totalMinutes % 60)
where % is MOD (ex: 15 MOD 4 = 3)
as far as I see, floor is same as truncate, and quick lookup gave, that MOD is MOD like A MOD B
i want to print missing records in crystal report .
i am using below formula in the report and i have placed this formula in details b section.
details a has normal report fields.
formula:
local numbervar firstemp; // first Emp#
local numbervar nextemp; // next Emp#
local numbervar diff; // difference between firstemp and nextemp
local numbervar increase; // increment for missing Emp#'s
local numbervar result;
increase := 0;
firstemp := tonumber({getRptSalesSummery;1.Bill_Id});
nextemp := tonumber(next({getRptSalesSummery;1.Bill_Id}));
nextemp := nextemp -1;
diff := nextemp - firstemp;
if nextemp = firstemp
then ""
else (
while diff >= 1
do (
diff := diff - 1;
increase := increase + 1;
result := firstemp + increase;
exit while;
);
totext (result,"0000") & chr(13);
)
this formula is not giving me range.
for example if in report there is range of 1 to 10 and 6,7,8,9 is missing records, then if i check in the report its printing 1 to 5 and 6 as missing then directly 10, but its not giving me 7,8,9.
basically i required range of missing records
I'm trying to convert a value in Cross-tab of Crystal report into a MM:SS format. I used the following steps: Right-click summary > Format Field > Display String > x+2
WhilePrintingRecords;
NumberVar curr := CurrentFieldValue;
NumberVar mins := Truncate(curr / 60);
NumberVar secs := Remainder(curr, 60);
ToText(mins, 0, "") & ":" & ToText(secs, 0, "")
The results are ok when the secs is not 0. Example: `4:30'
But, I am having problems when secs is 0, the result is (for 4 minutes): 4:0
I would like to have the output as 4:00, with the seconds display as always a 2 digit number.
Thank you for all your help
You my ElapsedTime function in conditional-formatting expression.
I used this instead, and it worked :)
NumberVar curr := CurrentFieldValue;
NumberVar mins := Truncate(curr / 60);
NumberVar secs := Remainder(curr, 60);
ToText(mins, 0, "") & ":" & ToText(secs, '00')
I've got a Crystal Report (2011) that uses a Stored Procedure to display some data. One of the fields is TimeSpent (bigint) and it holds the number of Ticks in a TimeSpan (in C#, we pass TimeSpan.Ticks to the DB to be stored).
Obviously on my report I wouldn't want to show this, so I am wondering how I can convert ticks to read dd:hh:mm:ss, e.g. 01:05:58:25 for 1 day, 5 hours, 58 minutes and 29 seconds?
A tick is 100 nanoseconds, or 10 million ticks per second. So first convert to seconds
numbervar span := {field.ticks}/10000000;
From there, just break the seconds down into time pieces (This snippet is from tek-tips):
numbervar days;
numberVar hrs;
numberVar min;
numberVar sec;
stringVar ddhhmmss;
days:= Truncate(Truncate(Truncate(span/60)/60)/24);
hrs := Remainder(Truncate(Truncate(span/60)/60),24);
min := Remainder(Truncate(span/60),60);
sec := Remainder(span,60);
ddhhmmss := totext(days,0,"") + ":" + totext(hrs,"00") + ":" + totext(min,"00") + ":" + totext(sec,"00");
ddhhmmss