Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: spot whats wrong with my bit of code please?? Post Reply Post New Topic
Author Message
marco007
Newbie
Newbie


Joined: 11 Jun 2013
Online Status: Offline
Posts: 17
Quote marco007 Replybullet Topic: spot whats wrong with my bit of code please??
     Posted: 01 Oct 2014 at 4:45am
Hi folks

can someone let me know please what is wrong with my code below?

I trying to create a calculated field that will output a certain value based on the value of another field, so if my JobMtl.totalCost is between.01 and 50 then I was to output a value of 67 in my calculated field. etc etc

If {JobMtl1.TotalCost} > .01 and if {JobMtl1.TotalCost} < 50 then 67 ELSE
If {JobMtl1.TotalCost} > 50.01 and if {JobMtl1.TotalCost} < 75 then 50 ELSE
If {JobMtl1.TotalCost} > 75.01 and if {JobMtl1.TotalCost} < 100 then 43 ELSE
If {JobMtl1.TotalCost} > 100.01 and if {JobMtl1.TotalCost} < 125 then 38 ELSE
If {JobMtl1.TotalCost} > 125.01 then 0


When I try to save code I'm using above it tells me the keyword Then is missing.

any help is appreciated.
IP IP Logged
z9962
Senior Member
Senior Member
Avatar

Joined: 04 Jul 2012
Online Status: Offline
Posts: 161
Quote z9962 Replybullet Posted: 01 Oct 2014 at 5:12am

you only need to write the first if for each line, ie IF {JobMtl1.TotalCost}> .01 and {JobMtl1.TotalCost} < 50 then 67 ELSE

 
Though a better way to write it might be:
If {JobMtl1.TotalCost} in .01 to 50 then 67 ELSE
If {JobMtl1.TotalCost} in 50.01 to 75 then 50 ELSE
If {JobMtl1.TotalCost} in 75.01 to 100 then 43 ELSE
If {JobMtl1.TotalCost} in 100.01 to 125 then 38 ELSE
0


Edited by z9962 - 01 Oct 2014 at 5:13am
IP IP Logged
marco007
Newbie
Newbie


Joined: 11 Jun 2013
Online Status: Offline
Posts: 17
Quote marco007 Replybullet Posted: 01 Oct 2014 at 5:14am
never knew i could do it that way.
works a treat.
thanks a million:)
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 02 Oct 2014 at 4:56am
For future reference, in your original formula, you just need "and", not "and if". It was this second "if" in each line that was causing the error. The correct version of the formula is this:

If {JobMtl1.TotalCost} > .01 and {JobMtl1.TotalCost} < 50 then 67 ELSE
If {JobMtl1.TotalCost} > 50.01 and {JobMtl1.TotalCost} < 75 then 50 ELSE
If {JobMtl1.TotalCost} > 75.01 and {JobMtl1.TotalCost} < 100 then 43 ELSE
If {JobMtl1.TotalCost} > 100.01 and {JobMtl1.TotalCost} < 125 then 38 ELSE
If {JobMtl1.TotalCost} > 125.01 then 0

-Dell
IP IP Logged
marco007
Newbie
Newbie


Joined: 11 Jun 2013
Online Status: Offline
Posts: 17
Quote marco007 Replybullet Posted: 02 Oct 2014 at 4:59am
thats great. thanks
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum