Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Variables Problem Post Reply Post New Topic
Author Message
viperbyte
Newbie
Newbie


Joined: 13 May 2013
Location: United States
Online Status: Offline
Posts: 38
Quote viperbyte Replybullet Topic: Variables Problem
     Posted: 23 May 2013 at 5:57am
Hello everyone, Happy Thursday.
 
I'm doing something that's not working and I think it's because my variable is being reintializing everytime a group happens.
 
I have this in a formula and I have this formula inserted into GroupHeader A:
NUMBERVAR COUNTER;
COUNTER:= COUNTER + 1
 
 
 
NUMBERVAR COUNTER;
 
I've tried putting the above in a formula that I put in the page header and putting COUNTER:= COUNTER + 1 in a formula so that I could put in the groupheader A area.  But when I try to save the formula that simply says COUNTER:= COUNTER + 1   I get the "The remaining text does not seem to be part of a formula" error.  How do I break these two lines up? 
 
I need to break it up becuause by having them together in a formula such as
NUMBERVAR COUNTER;
COUNTER:= COUNTER + 1
 
which I place in GroupHeaderA isn't working and I beleive it's because of reinitializing.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 23 May 2013 at 12:35pm
Originally posted by viperbyte

I have this in a formula and I have this formula inserted into GroupHeader A:
NUMBERVAR COUNTER;
COUNTER:= COUNTER + 1
 
 
 
NUMBERVAR COUNTER;
 
 
Why do you have the second "NUMBERVAR COUNTER;" in here?  I suspect that the real problem is that you're never initializing the variable to 0, so it's value is really "null".  When you add something to null, you still get null!
 
So, you'll need two or three formulas - one that will initialize the variable to 0, one that will increment it, and one that will display it.  They'll look like this:
 
{@InitCounter}
WhileReadingRecords;
NumberVar COUNTER := 0;
 
Place this in the Report header section to initialize it at the beginning of the report. (even if the report header is suppressed, the variable will be initialized.  Because of the semi-colon at the end, the value won't actuall appear on the report.
 
{@AddCounter}
WhileReadingRecords;
NumberVar COUNTER;
COUNTER := COUNTER + 1;
 
Place this in your group header.  If you want the value to appear on the report, take the semi-colon off the end.
 
{@ShowCounter}
WhileReadingRecords;
NumberVar COUNTER
 
If you want to show the value of the of the variable in a section other than where it's being incremented, create this third formula to show it.
 
-Dell
 
 
IP IP Logged
viperbyte
Newbie
Newbie


Joined: 13 May 2013
Location: United States
Online Status: Offline
Posts: 38
Quote viperbyte Replybullet Posted: 23 May 2013 at 11:54pm
Thank you very, very much for the lesson.  I really appreciate it.
 


Edited by viperbyte - 23 May 2013 at 11:54pm
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