Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Do While Looping in SubRPT Post Reply Post New Topic
Author Message
KSAnalyst
Newbie
Newbie
Avatar

Joined: 04 Mar 2008
Location: United States
Online Status: Offline
Posts: 29
Quote KSAnalyst Replybullet Topic: Do While Looping in SubRPT
     Posted: 19 Apr 2012 at 6:13am
Hi CRXI Gurus,
 

My purpose is to find out after a client is discharged from an inpatient unit when and where are their next 3 outpatient services.

 

1.       I have a report with a main report that shows inpatient discharges only. Then a subreport with next outpatient service in the group header.

2.       I now need to find the next 3 outpatient services.

a.       I tried a DO/While loop with a counter but I am getting a count of 2 every time.  Here is my code:

 

StringVar Array ServiceCnt;

StringVar SVCNT;

NumberVar CNTR:= 1;

While CNTR < 3 Do

(

    SVCNT:= if  (previous ({billing_tx_history.date_of_service}) <> {billing_tx_history.date_of_service} and

                previous ({billing_tx_history.SERVICE_CODE})<> {billing_tx_history.SERVICE_CODE}) then

                {billing_tx_history.program_code}&"    " &{billing_tx_history.program_value}&"    " & {billing_tx_history.date_of_service}&"    "& {billing_tx_history.SERVICE_CODE}&"    " & {billing_tx_history.v_service_value}&  CNTR;

    CNTR:=CNTR+1;

);

SVCNT;

 

It seems an easy enough concept but I just don’t know the coding well enough.

Thank you for your help in advance

Kevin
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 19 Apr 2012 at 7:12am
if everything is fine, then you want either
while CNTR <= 3 or
while CNTR < 4
 
when CNTR = 2, it is in the loop. When it is incremented to 3...well 3 is not less than 3, so it stops
 
HTH
 
 
IP IP Logged
KSAnalyst
Newbie
Newbie
Avatar

Joined: 04 Mar 2008
Location: United States
Online Status: Offline
Posts: 29
Quote KSAnalyst Replybullet Posted: 19 Apr 2012 at 7:16am
Thanks Lockwelle,
 
I forgot to mention that eventhough the cntr is 2, I get more than 3 records in the details of the subreport.  I think it has to to with the "previous" condition and when the loop hits a duplicate, it then counts and resets before printing the next record.  What do you think?
 
Just a guess.
 
Thanks
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 19 Apr 2012 at 11:41am
if this is in the detail section, you would get probably as many entries as there are rows.  Also, the previous function does not respect group boundaries, so that could cause some issues.
 
I would think that you would want to put the display portion in a group footer, but each detail row will add to the SVCNT.  I would put the initialization of CNTR in a section prior to the detail section...probably the group header. This way the value of the CNTR will always be >3 once you get the first 3.
 
HTH
IP IP Logged
KSAnalyst
Newbie
Newbie
Avatar

Joined: 04 Mar 2008
Location: United States
Online Status: Offline
Posts: 29
Quote KSAnalyst Replybullet Posted: 19 Apr 2012 at 12:14pm
Thank you I will give it a try.
 
I appreciate your help.
 
K  LOL
IP IP Logged
kammertime
Newbie
Newbie


Joined: 18 Jun 2012
Online Status: Offline
Posts: 3
Quote kammertime Replybullet Posted: 19 Jun 2012 at 8:19am
I have a question about the use of the "previous" command in the do loop.
Does it return the prior record each time it executes the "previous" command in the do loop ?
 
for example:
current record is 4. Will executing the do loop then return record 3, then record 2, then record 1?
 
Thanks,
John
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 20 Jun 2012 at 7:08am
no, it will only back to record 3.
 
you have to be on record on 3 for it to return record 2
 
it only goes back or forward(next) 1 record...and the only caveat is that the command does not care about group boundaries, so some results make no sense.
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