Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Failing formula Post Reply Post New Topic
Author Message
sirlansa
Newbie
Newbie
Avatar

Joined: 20 Dec 2006
Location: United States
Online Status: Offline
Posts: 37
Quote sirlansa Replybullet Topic: Failing formula
     Posted: 14 Feb 2008 at 2:12pm
I am running CR 10 and trying to create a formula, that keeps falling thru the condition that it should stop on: eg here is part of the formula text....
 
                IIf(({vCSMain.Count}=0 And {vCSMain.SoldSet}=0 And {@CurSetAdjMIN}=0),
                        50000,
                        IIf(({vCSMain.Count}=0 And {vCSMain.SoldSetAdjusted}>0 And {@CurSetAdjMIN}=0),
                                {vCSMain.Days}/{vCSMain.SoldSet},
                               IIf(({vCSMain.Count}=0 And {vCSMain.SoldSet}=0 AND 0">{@CurSetAdjMIN}>0),
                                        ({@CurSetAdjMIN}*{vCSMain.Days})* 10,
                                        IIf(({vCSMain.Count}=0 AND 0">{@CurSetAdjMIN}>0 AND {vCSMain.SoldSet}>0),
                                                (
{vCSMain.Days}*{@CurSetAdjMIN})/{vCSMain.SoldSet},
                                                IIf(({@CurSetAdjMIN}<=0 And {vCSMain.SoldSet}<=0),
                                                        {vCSMain.Days}/({vCSMain.Count}*{vSalesConfidence.80PercentSales}),etc.
 
When it blows up (DIV by 0 on last line), the debug information window shows:
Count = 0
SoldSet = 16
@CurSetAdjMIN = 14
 
Why doesn't the formula end (on line in bold above) BEFORE it gets to the divide by 0, due to Count being 0?
 
PS please ignore hyperlinks and extraneous chars gratuitously supplied by the editor, ie, 0''>
 
Does anyone see something I don't see?? I've checked for control characters by pasting into Notepad and back. Always get the same error.
Thanks,
Sirlansa
Sir Lansa
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 14 Feb 2008 at 4:49pm
Man, what a mess of nested IIFs!

Anyway, I have no idea why this is happening, but what I would do in this case is debug it by doing a test strictly on the Count field within the True condition of that IIF() condition. That way you try trapping it again when it is by itself. Thus, some of the other variables wouldn't have the ability to effect the outcome. Again, it's just a means of doing more testing and isolating the problem since the statement looks pretty logical.
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
sirlansa
Newbie
Newbie
Avatar

Joined: 20 Dec 2006
Location: United States
Online Status: Offline
Posts: 37
Quote sirlansa Replybullet Posted: 20 Feb 2008 at 7:10am

Brian,

I think I know why this is happening! In a Crystal syntax formula, ALL the expressions appear to be evaluated prior to any conditional execution. That's why the DIV0 occurs even though that line would never be executed. I'm hoping that the VB syntax will work differently.

Sir Lansa
IP IP Logged
sirlansa
Newbie
Newbie
Avatar

Joined: 20 Dec 2006
Location: United States
Online Status: Offline
Posts: 37
Quote sirlansa Replybullet Posted: 20 Feb 2008 at 7:23am
Doing the formula in VB works!!
Sir Lansa
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