Writing Code
 Crystal Reports Forum : Crystal Reports .NET 2003 : Writing Code
Message Icon Topic: if then Formula issue with crystal report 8.5 Post Reply Post New Topic
Author Message
yasinirshad
Newbie
Newbie
Avatar

Joined: 24 Sep 2007
Location: Saudi Arabia
Online Status: Offline
Posts: 39
Quote yasinirshad Replybullet Topic: if then Formula issue with crystal report 8.5
    Posted: 31 May 2008 at 3:42am
Hi,
Am saving values(0 OR 1) in db in a Table , say 'TableA' under columns 'ABC','DEF','XYZ'
ABC DEF XYZ
1       1      0
 
AM USING THIS FORMULA,
 
if ({eC_IRFDetails.ABC}) = 1 then
"Capacity Expansion"
else
if ({eC_IRFDetails.DEF}) = 1 then
"Productivity"
else if ({eC_IRFDetails.XYZ}) = 1 then
"Replacement"
 
MY ISSUE IS THAT , WHEN 'ABC' AND 'DEF' IS '1' IN DB THEN IT ONLY SHOWS "Capacity Expansion" and does not show "Productivity" in my report..why?
 
Thanks to help.
Thanks,
Yasin.
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 31 May 2008 at 8:27pm
A formula can only return a single variable. Not only that, but you are using "If-Else" statements which means that once the first condition is a success, then it won't even look at the other conditions.

In your example, you are returning a single string based upon the value of one of the fields. If you want to show both values, how do you plan on doing it? The formula can result can be shown once. I suggest concatenating the variables together and separating them with a space (adding a comma at the end gets tricky b/c you might have to strip it off at the end). Here is a quick fix to your formula that might work for you:
StringVar Result;
if ({eC_IRFDetails.ABC}) = 1 then
Result := "Capacity Expansion";

if ({eC_IRFDetails.DEF}) = 1 then
Result := Result + " Productivity" ;

if ({eC_IRFDetails.XYZ}) = 1 then
Result := Result + " Replacement";

Result;


Try this and see if it is the fix you need. I cover programming formulas spanning  3 chapters in my CR Encyclopedia book. You can find out more about my books at Amazon.com or reading the Crystal Reports eBooks online.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.031 seconds.