Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: formula error Post Reply Post New Topic
Author Message
christoph
Newbie
Newbie


Joined: 07 Jul 2009
Location: United Kingdom
Online Status: Offline
Posts: 6
Quote christoph Replybullet Topic: formula error
     Posted: 05 Aug 2009 at 3:14am
I have written a number of reports recently on Crystal XI R1 which work fine however one report errors when I run it on the Crystal Viewer I've written. The viewer was written in Visual Studio 2005 but incorporating the appropriate EmbeddedReporting merge module. The error is as follows:
 
Error in Formula <detailLines>
 
'Whileprintingrecords;
'
 
A number, currency, amount, boolean, date, time, date-time or sting is expected here.
 
This formula is one of three that calculate the length or records so that page breaks are correctly thrown. The formulas as as follows:
 
<PageLines>
//reset page length
whileprintingrecords;
shared numbervar size := 0;
 
<grouplines>
//calculates header
whileprintingrecords;
shared numbervar size;
size := size + 0.91;
 
<detailLines>
//the height of two fields are calculated based on characters per line * //height per line
whileprintingrecords;
shared numbervar size;
size := size + 2.74;
size := size + ceiling(length({DCApr.Proposal})/95) * 0.63;
size := size + ceiling(length({@agents})/95) * 0.63;
 
The value of size is then used to control the group header's New Page Before formula as follows:
 
whileprintingrecords;
shared numbervar size;
24.7 - size <= 6;
 
i.e if page length - size is <= 6 throw a page break.
 
I suspect there is a problem with the formula but I would appreciate advice as to why the viewer is erroring since it uses the same dll versions as Crystal XI. It also uses the CRRedist2005_x86.msi package that is part of VS 2005.
 
Thanks
Chris
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 05 Aug 2009 at 6:32am
since the error is in detailLines, I would suspect the lines with ceiling in them.  for the length, neither is NULL are they?  I am not sure how length plays with NULL. One would think 0, but...
 
Also, maybe it is just paranoia, but 'size' bothers me. If the above isn't true, I would try changing the variable name.
 
HTH
IP IP Logged
christoph
Newbie
Newbie


Joined: 07 Jul 2009
Location: United Kingdom
Online Status: Offline
Posts: 6
Quote christoph Replybullet Posted: 05 Aug 2009 at 7:32am

Thanks for the suggestion Lockwelle. I have updated the formula by changing the variable name to recSize and also putting the following conditionals round the calculations:

//working section
whileprintingrecords;
shared numbervar recSize := recSize + cdbl(2.74);
//conditional
if (length({DCApr.Proposal}) <> 0 ) then
    recSize := recSize + ceiling(length({DCApr.Proposal})/95) * 0.63;
 
if (length({@agents}) <> 0) then
    recSize := recSize + ceiling(length({@agents})/95) * 0.63;
N.B. Neither field should be null and the @agent formula puts an alternative value in.
 
Unfortunately this is still bombing out on the viewer.
 
Thanks
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 05 Aug 2009 at 1:21pm
the last suggestion is to validate the values...this is all in a formula, I would place the formula on the report and have it display the various values.  If that doesn't help. I would start breaking up the formula and displaying those values.
 
whenever I can't figure out why something isn't working, I start having Crystal display the values, it may be that all is as I supposed it was, and it was just my logic that was flawed, but sometimes it is just that the data is doing something that I wasn't expecting.
 
Hope this helps.
IP IP Logged
christoph
Newbie
Newbie


Joined: 07 Jul 2009
Location: United Kingdom
Online Status: Offline
Posts: 6
Quote christoph Replybullet Posted: 06 Aug 2009 at 3:01am
Thanks Lockwelle for the suggestion..after some rather long winded debugging I have identified the issue. It appears that there may be a bug in the redistributable in that it does not seem to run either the ceiling or roundup functions correctly and so the return value was not return, hence the error message.
 
Anyway the round function does work so combining with the remainder function I was able to correctly round the values so that the new page formula works correctly. The working formula looks like this:
 
if (length({DCApr.Proposal}) < 95 ) then
        shared numbervar recSize := recSize + 0.63
else if (remainder((length({DCApr.Proposal})/95),1) < 1) then
        shared numbervar recSize := recSize + (round(length({DCApr.Proposal})/95)+1) * 0.63;
 
Thanks again for the help.
 
Chris
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