Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Division by Zero error

Status
Not open for further replies.

newbie0423

IS-IT--Management
Oct 29, 2012
103
US
Hello,
I'm using Crystal XI
I'm writing a report that looks at the time a patient leaves the room until the time the next patient comes into the room (turnover time). Below are the formulas that I am using to get the average turnover time.
@average
WhilePrintingRecords;
Global NumberVar TotalHours;
Global NumberVar WorkOrderCount;
TotalHours / WorkOrderCount;

WorkOrderCount := WorkOrderCount + 1

@turnover

WhilePrintingRecords;
Global NumberVar TotalHours;
Global NumberVar WorkOrderCount;
Local NumberVar currentdiff;

if {@turnover} > 60 or {@turnover} = 0 then
currentdiff := 0
else
(
currentdiff := {@turnover};
TotalHours := TotalHours + currentdiff;
WorkOrderCount := WorkOrderCount + 1
);
currentdiff;

The average formula gets a division by zero error message. Could someone please tell me how to handle this error message

Thanks in advance
 
newbie043,

You will need to build an catch into your first formula, to check when "WorkOrderCount" is zero, due to the text in red (which as best I can tell, doesn't do anything at present -- not sure why it is there)

Code:
@average
WhilePrintingRecords;
Global NumberVar TotalHours;
Global NumberVar WorkOrderCount;
[red]TotalHours / WorkOrderCount;[/red]

WorkOrderCount := WorkOrderCount + 1

You will need something like "IF workordercount=0 THEN [something] ELSE [what you currently have]". That being said, I am not sure why that line is in the formula - it calculates the value, but doesn't assign it to anything and because it isn't the last line in the formula, I am pretty sure that formula will always return the current workordercount, NOT the result of that division.

Hope this helps! Cheers!

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
Thanks for responding Mike. I tried IF workordercount=0 THEN {@turnover2} ELSE workordercount. I took out the TotalHours / WorkOrderCount; the report comes up blank.

 
Hmmm. I must have missed something, my apologies.

I have been back and forth in my head a few times now, and I think that it is a different concern... an average cannot be calculated unless there are Hours, which I assume are Hours on a Work Order. By that logic, you cannot have one without the other. Perhaps WorkOrderCount needs to be "RESET" at 1 instead of zero OR you need to increment it before the calculations?

Failing all else, a reverse look at the catch (and putting the division back in -- never considered it pulling data from another formula) is all that is needed.

How about:
{@Average}
Code:
WhilePrintingRecords;
Global NumberVar TotalHours;
Global NumberVar WorkOrderCount;
IF WorkOrderCount<>0 THEN
( 
    TotalHours / WorkOrderCount;
)

WorkOrderCount := WorkOrderCount + 1

If none of this helps, perhaps you could provide some more information as the the report stucture itself --- maybe there is an simpler way, or a different approach that could be implemented.

Item of note: you refernce a {@Turnover2} in your last reply, but the original post has {@turnover} referenced within itself... can you please provide clarity around which formula has the two and provide details of the other? This may also help out.

Cheers!

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
Mike I REALLY appreciate your help. The formula that you gave me works in that the I'm not getting the division by zero error message, but it is not computing the average correctly. I'm using the two formulas below to arrive at my turnover time.

@turnover

if OnfirstRecord then
0

Else if Date({v_basic_case_rec_data.cr_prdate}) <> Date(Previous({v_basic_case_rec_data.cr_prdate}))then
0
Else if {v_basic_case_rec_data.room_mnc} <> Previous({v_basic_case_rec_data.room_mnc}) then
0
else
if previous ({@PtOutTime}) > {@roomrdy}then
0
else
IF {v_basic_case_rec_data.room_mnc} = PREVIOUS ({v_basic_case_rec_data.room_mnc})
THEN ({@roomrdy} - PREVIOUS ({@PtOutTime}))/60

and
@turnover2

WhilePrintingRecords;
Global NumberVar TotalHours;
Global NumberVar WorkOrderCount;
Local NumberVar currentdiff;

if {@turnover} > 60 or {@turnover} = 0 then
currentdiff := 0
else
(
currentdiff := {@turnover};
TotalHours := TotalHours + currentdiff;
WorkOrderCount := WorkOrderCount + 1
);
currentdiff.

I'm actually using the second one the report,


Thanks,
Val
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top