Print Page | Close Window

Subreport with IF/THEN statement

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=19798
Printed Date: 29 Apr 2024 at 1:04pm


Topic: Subreport with IF/THEN statement
Posted By: crystalsonic
Subject: Subreport with IF/THEN statement
Date 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
 



Replies:
Posted By: lockwelle
Date 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



Print Page | Close Window