| Author |
Message |
mac-duff
Newbie
Joined: 22 Apr 2010
Location: Spain
Online Status: Offline
Posts: 21
|

Topic: Merge two formulas Posted: 05 May 2010 at 10:54am |
Hello, can please someone tell me how it is possible to merge this two formulas to one? @TiempoMarcha
If {Produccion.Estado} = "On" then {Produccion.TiempoParo} else 0
@TiempoMarchaDisplay
NumberVar TotalSec := Sum ({@TiempoMarcha}, {CambioTurno.IdEquipo});
NumberVar Hours := Truncate ( TotalSec / 3600); NumberVar Minutes := Truncate (Remainder ( TotalSec,3600) / 60); NumberVar Seconds := Remainder (TotalSec , 60) ;
Totext ( Hours, '####') + ':'+ Totext ( Minutes,'00') + ':' + Totext ( Seconds , '00' )
Thanks
|
IP Logged |
|
|
|
hilfy
Admin Group
Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
|

Posted: 05 May 2010 at 12:13pm |
This should work correctly as is unless {Produccion.Estado} can be null. In which case you want to change it to something like this:
If IsNull({Produccion.Estado}) or {Produccion.Estado} <> "On" then 0 else {Produccion.TiempoParo}
What is happening that is not working correctly? If you get an error message, please post it.
-Dell Edited by hilfy - 05 May 2010 at 12:13pm
|
|
|
IP Logged |
|
overcharge
Newbie
Joined: 12 Mar 2010
Location: Malaysia
Online Status: Offline
Posts: 12
|

Posted: 05 May 2010 at 6:10pm |
I did not know this will be work fine, but i think you can give it a try. NumberVar TotalSec := Sum ({@TiempoMarcha}, {CambioTurno.IdEquipo});
NumberVar Hours := Truncate ( TotalSec / 3600); NumberVar Minutes := Truncate (Remainder ( TotalSec,3600) / 60); NumberVar Seconds := Remainder (TotalSec , 60) ;
if {Produccion.Estado}="On" then Totext ( Hours, '####') + ':'+ Totext ( Minutes,'00') + ':' + Totext ( Seconds , '00' ) else '0'
|
IP Logged |
|
mac-duff
Newbie
Joined: 22 Apr 2010
Location: Spain
Online Status: Offline
Posts: 21
|

Posted: 05 May 2010 at 8:49pm |
|
Hi,
thanks for the answers. I guess u havent understood me correctly. I have this two formulas @TiempoMarcha and @TiempoMarchaDisplay and I call in @TiempoMarchaDisplay the first formula @TiempoMarcha which means I would like to replace in the second formula the statement "@TiempoMarcha" directly with the formula.
If I just place it there the error is that is has to be a field
|
IP Logged |
|
Nissim
Newbie
Joined: 04 May 2010
Online Status: Offline
Posts: 18
|

Posted: 05 May 2010 at 9:24pm |
|
Very helpful. thanks.
|
IP Logged |
|
hilfy
Admin Group
Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
|

Posted: 06 May 2010 at 4:09am |
Do you have a group on {CambioTurno.IdEquipo}? If not, that's your problem.
Because you need to do the sum, you can't merge the first formula into the second. Also, the Sum needs to be calculated before the rest of the formula and that doesn't necessarily happen correctly when it's in the same formula as the rest of it. You can use the WhileReadingRecords and WhilePrintingRecords special clauses to tell Crystal when to process things. Summary formulas are automatically calculated while reading the data, so I would split the sum out into it's own formula - I'll call it @TotalSeconds wand it looks like this: Sum ({@TiempoMarcha}, {CambioTurno.IdEquipo})
Then your @TiempoMarchaDisplay formula will be this:
This way it will be processed after the value for the sum is already known. I haven't tested this, but it should work.
-Dell
|
|
|
IP Logged |
|
mac-duff
Newbie
Joined: 22 Apr 2010
Location: Spain
Online Status: Offline
Posts: 21
|

Posted: 10 May 2010 at 11:05am |
|
Hi hilfy,
u tell me exact the same way I wrote in my first post ;) and I wanted to know is it possible to get it into one formula only or is it a constriction of Crystal Reports?
|
IP Logged |
|
hilfy
Admin Group
Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
|

Posted: 10 May 2010 at 3:44pm |
No, you can't get it into a single formula. And no, what I posted is NOT the exact same way as you first posted - I broke it down one level further. The sum and the rest of the second formula need to be processed separately so you'll end up with THREE formulas.
You need to move the SUM from your second formula into it's own formula with "WhileReadingRecords;" at the top and the rest of your second formula in its own formula with "WhilePrintingRecords;" at the top.
-Dell Edited by hilfy - 10 May 2010 at 3:45pm
|
|
|
IP Logged |
|
|
|