Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Subreport with IF/THEN statement Post Reply Post New Topic
Author Message
crystalsonic
Groupie
Groupie


Joined: 26 Jan 2012
Online Status: Offline
Posts: 46
Quote crystalsonic Replybullet Topic: Subreport with IF/THEN statement
    Posted: 22 Jul 2013 at 11:23am
I am using a subreport to display codes horizontally. These are my formulas:
FORMULA #1
    WhilePrintingRecords;
    StringVar chain := '';
    NumberVar ChCnt := 1
 
FORMULA #2
    WhilePrintingRecords;
    StringVar Item:= {DoctorClientIndex.Client}; 
    StringVar Chain;
    NumberVar ChCnt;
    if ChCnt = 1
    then (ChCnt:= 2; chain := Item)
    else
    if Length(Chain) + Length(Item) > 254
    then Chain := Chain else
    chain := chain + '^' + Item
 
FORMULA #3
    WhilePrintingRecords;
    StringVar Chain
 
This works fine, except I need to add a code under certain conditions. I changed FORMULA #3 to the following:
    If {Doctors.ClientInd} = 0 then StringVar Chain else
    If {Doctors.ClientInd} = 2 then {Doctors.Doctors1}&'^'&StringVar Chain
 
Again, this works fine. The problem is when the Chain variable is blank I still need it to display the Doctors.Doctors1 by itself.
 
This is what the report looks like:
 
Doctors.Doctors1     Doctors.Client Ind     Subreport
A1                             2                               A1^180061^D1
A104                         0                               C197^M180
A15                           2                              
 
 
This is what it shoudl be:
Doctors.Doctors1     Doctors.Client Ind     Subreport
A1                             2                               A1^180061^D1
A104                         0                               C197^M180
A15                           2                               A15
 
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 24 Jul 2013 at 5:04am
I'm not sure if this would help, but...

   WhilePrintingRecords;
    StringVar Chain
    If {Doctors.ClientInd} = 0 then
      Chain
    else
       If {Doctors.ClientInd} = 2 then
          {Doctors.Doctors1} &'^'& Chain;

Sorry, I like to indent for readability, I also hate to declare a variable more than once.

Unless Chain is NULL, it should concatenate just fine...so if this doesn't work, I would check if Chain is NULL.

For a quick check you could easily add at the end of Formula3:

ISNULL(Chain)

and this will print a true or false instead of the chain string...just a way to check that everything is as you think it is.

If it is NULL, remember to check for NULLs BEFORE checking other values, as the NULL value will trump the other checks, as DBlank has mentioned several times (I think CR is throwing an error that it catches and ignores, but either way it causes CR to behave in an unpredictable way).

HTH
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.016 seconds.