Lockwelle,
I've used your code and with a little modification it now works !
It's been a steep learning curve but I'm begining to get to grips Crystal Reports and can see me using it a lot as time goes by.
Thanks again for your invaluable help.
The finished codeis this:
Header Section
// Flag set to indicate first record being read
shared booleanVar FirstRecord:= TRUE;
// Array to hold accumulated time periods in seconds for each status (0-10)
shared numberVar array StatusArray;
redim StatusArray [11];
// Status descriptions (0-10) held in second array
Shared stringVar array StatusNames := [
'Unknown ',
'Stopped ',
'Stopped in alarm ',
'Status 3 (Future) ',
'Status 4 (Future) ',
'Status 5 (Future) ',
'Status 6 (Future) ',
'Waiting for upstream line ',
'Running in alarm ',
'Running empty ',
'Running '
];
// Hide the output
""
Deatil Section
// Variable declarations
// External from header
shared booleanVar FirstRecord;
shared numberVar array StatusArray;
// Last Scan
shared dateTimeVar LastTime;
shared numberVar LastStatus;
// This Scan
local dateTimeVar ThisTime;
local numberVar ThisStatus;
// Scan Results
local numberVar Status;
local numberVar Period;
// Totaliser
local numberVar Status;
local numberVar Period;
local numbervar Index;
// Read time and status from current record
ThisTime := {LinesStatus.TimeCol};
ThisStatus := {LinesStatus.Status};
// Check for first record
IF FirstRecord = TRUE
THEN
// Take a snapshot of current record on first scan
(LastStatus := ThisStatus;
LastTime := ThisTime)
ELSE
// Calculate period and status on all other scans
( Period := datediff("s", LastTime, ThisTime);
Status := LastStatus;
LastStatus := ThisStatus;
LastTime := ThisTime);
// Reset first record flag
FirstRecord:= FALSE;
// Assemble results into an array (Offset by 1 to cope with Status 0)
StatusArray[STATUS + 1]:= StatusArray[STATUS + 1] + Period;
// Hide the output
""
Footer Section
// External variable from header
shared numberVar array StatusArray;
shared stringVar array StatusNames;
// Result string
local stringvar Result := "";
// Loop to assemble each status/period
local numbervar i;
FOR i := 1 to 11 step 1 do(
if StatusArray <> 0 then (
Result := Result & totext((i-1), 0,"") & chrw(9); // Status number and tab
Result := Result & StatusNames & chrw(9); // Status description and tab
Result := Result & totext((StatusArray), 0,""); // Period at status (in seconds) and tab
Result := Result & " Secs" & chrw(13) & chrw(10); // Add units and LF/CR
);
);
// Output the result
Result