Print Page | Close Window

Basic If statement with Variable

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=5407
Printed Date: 17 May 2024 at 8:09pm


Topic: Basic If statement with Variable
Posted By: 03-636
Subject: Basic If statement with Variable
Date Posted: 04 Feb 2009 at 6:47am
Hello,
I'm currently trying to create a report for out machine shop that will let them know the % of late and on time work orders.  The fallowing if statement is what I have come up with.

numberVar A :=0 ;
numberVar B :=0 ;
if {WOL_WorkOrderHistoryHeader.ClosedDate} <= {WOL_WorkOrderHistoryHeader.WODueDate} then A = A+1
else
if {WOL_WorkOrderHistoryHeader.ClosedDate} > {WOL_WorkOrderHistoryHeader.WODueDate} then B = B+1;
B/A

I put this in the detail line and the only output im getting back for A and B is a 0.
Im very new to crystal but have a small amount of programming background. Thanks for the help ahead of time!




Replies:
Posted By: DBlank
Date Posted: 04 Feb 2009 at 7:28am
You can handle this using a by just using a 3 summary counts. NOt sure if you are grouping so you will have to adjust where you put the summaries if you are.
create a formula to get your ontime records:
if {WOL_WorkOrderHistoryHeader.ClosedDate} <= {WOL_WorkOrderHistoryHeader.WODueDate} then 1 else 0
Create a summary SUM of this to get the ontime total.
create a formula to get your late records:
if {WOL_WorkOrderHistoryHeader.ClosedDate} > {WOL_WorkOrderHistoryHeader.WODueDate} then 1 else 0
Create a summary SUM of this to get the ontime total.
 
Create a summary COUNT of all your records.
 
Create a formula to get your ontime percentage using the SUM of ontime % count of all.
SUM(@ontime)%COUNT(Allrecordfield)
Create a formula to get your late percentage
SUM(@ontime)%COUNT(Allrecordfield)
Place these on your report or group footer according to your set up


Posted By: 03-636
Date Posted: 04 Feb 2009 at 10:14am
thanks alot for the help.  It work great!



Print Page | Close Window