?
Solved

Reset variable after each group not working

Posted on 2008-10-06
9
Medium Priority
?
5,373 Views
Last Modified: 2012-05-05
Hi Experts,

Having trouble reseting a variable.  The formula (from mlmcc) works for each detail record however I can not reset the formula between each group.  The formula is:

WhilePrintingrecords;
Global DateVar LastHSDate;
Global NumberVar DaysSince;
If {cp_PS90DayReport;1.SvcID}= 'HS' then
(
    If (LastHSDate = Date(1900,01,01)) then
        DaysSince := 0
    else
        DaysSince := DateDiff('d',LastHSDate,{@convdatetime});

    LastHSDate := {@convdatetime};
)
else
(
    DaysSince := 0;
    LastHSDate := LastHSDate;
);


DaysSince

The formula is in the detail section.  Have tried a reset in the group header but it always shows as zero.

The orginal question is here:

http://www.experts-exchange.com/Database/Reporting_/Crystal_Reports/Q_23657542.html.

What happens is the number of days is being carried forward from one group to the next.  Note that I suppress displaying the formula if the number is less than zero (doubt this matters, just FYI).
Basic beginner with variables.

Thanks in advance.

LBarrett
0
Comment
Question by:LBarrett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 22657046
It looks like you need to move the reset formula field from the report header to  the group header.
( to reset the date field - is that what your problem is?)



0
 
LVL 101

Expert Comment

by:mlmcc
ID: 22659513
Do you get the 0 with the data you provided in the other questiion?

mlmcc
0
 

Author Comment

by:LBarrett
ID: 22662903
peter57r

Had the reset formula in the group header - it always displayed zero.  The reset formulas I tried were
if {cp_PS90DayReport;1.AdmSys}<> Previous ({cp_PS90DayReport;1.AdmSys})
then Global NumberVar DaysSince :=0;

and

WhilePrintingrecords;
Global NumberVar DaysSince:=0;

Neither worked, they always returned zero.

mlmcc

What happens is the formula will stay 0 until the condition is met and then it will display the correct number of days.  Then the next group (Patient) that meets the =HS condition is showing the # of days since the previous condition was true.  Each patient can have more than 1 HS type visit in the date range and the first HS visit for each patient should be zero

This is how it is:

Patient A
Visit Type     Date        #Days
HS               1/17/08        0                this is correct
H1               1/21/08
P4               1/23/08

Patient B
P4                1/15/08
No HS visit

Patient C
H1               1/21/08
HS               1/24/08        7                 this should be zero
H2               1/25/08

Patient D
No HS Visit

Patient E
HS                1/21/08       -3                 this should be zero
H4                1/22/08

Patient F
HS                1/15/08       -6                 this should be zero

Patient G
HS                 1/17/08        2                 this should be zero


This is what it should look like:

Patient A
Visit Type     Date        #Days
HS               1/17/08        0
H1               1/21/08
P4               1/23/08

Patient B
P4                1/15/08
No HS visit

Patient C
H1               1/21/08
HS               1/24/08        0
H2               1/25/08
HS               1/28/08        4

Patient D
No HS Visit

Patient E
HS                1/21/08       0
H4                1/22/08

Patient F
HS                1/15/08       0
HS                1/25/08       10

Patient G
HS                 1/17/08        0

Hope this helps to clarify.  I am also unsure why the reset formulas didn't help.  As stated I am fairly "beginner" with variables.

As for the other question I thought the formula was working correctly but since, this I have gone back to look and realize that is doing the same thing.  Didn't see it because the formula was suppressed if <0 and there were always 2nd and 3rd visits that calculated correctly.

LBarrett
     
0
Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

 

Author Comment

by:LBarrett
ID: 22662931
The question has become more difficult so I am raising the points.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 22663449
Try this in the patient group header as the reset

WhilePrintingrecords;
Global DateVar LastHSDate;
Global NumberVar DaysSince;
LastHSDate := Date(1900,01,01);
DaysSince := 0;
''

mlmcc
0
 

Author Comment

by:LBarrett
ID: 22663912
This works unless the group is more than one page.  I have the "Repeat Group Header on each page" checked.  If  I remove the check then the reset works correctly.  Otherwise it starts over again on each page at zero.  Put it in the group footer and that seems to work.  Any issues you can see with having it in the last group footer?
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 2000 total points
ID: 22664258
You can change the formula to

WhilePrintingrecords;
Global DateVar LastHSDate;
Global NumberVar DaysSince;
If Not InRepeatedGroupHeader then
(
    LastHSDate := Date(1900,01,01);
    DaysSince := 0;
)
''

mlmcc
0
 

Author Comment

by:LBarrett
ID: 22664901
Tried this:
WhilePrintingrecords;
Global DateVar LastHSDate;
Global NumberVar DaysSince;
If Not InRepeatedGroupHeader then
(
    LastHSDate := Date(1900,01,01);
    DaysSince := 0;
)
''
Had to add semicolon after last close paren and then it worked great.

Thanks again mlmcc it's just what I needed.

LBarrett
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 22665716
Sorry.  I missed that.

mlmcc
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question