Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking a condition on Multiple fields & Returning Multiple Comments 1

Status
Not open for further replies.

RedSparks

Technical User
Nov 6, 2003
24
US
I am wanting to create a formula/loop? that will check for a true condition on multiple fields and then return a comment for each field who's condition equals true. The if statement doesn't work because it will only return the first true statement it hits.

I'm working in Crystal 8.5

Example: fields to check for the "T" or "F" condition -

IF FS_S is "T" then return "self" or if FS_ADS is "T" then return "ADS" or if FS_G is "T" then "Guardian", or if FS_FM is "T" then "Family".

There are 7 fields that I'm checking for a true statement. For each "true" I want a string returned.
Such as: "Self, ADS, Guardian" - This is what I want displayed on the report.

 
use a variable to buiold up the string i.e.

Code:
//@TestString
WhilePrintingRecords;

StringVar MyString := "";

{
If FS_S = "T" Then MyString := "Self"
);
{
If FS_ADS = "T" Then 
 if mystring <> "" then mystring := mystring + ", ";
 MyString := mystring + "ADS"
);
{
If FS_G = "T" Then 
 if mystring <> "" then mystring := mystring + ", ";
 MyString := mystring + "Guardian"
);

etc..

MyString /end the formula with this to display the final string.

HTH


Gary Parker
MIS Data Analyst
Manchester, England
 
This is what I wrote:

WhilePrintingRecords;

StringVar MyString := "";

(If {FD__ADS_NEGOTIATED_SRVC_AGRMNT.SF_B_FS} = "T" Then MyString := "Self");
(If {FD__ADS_NEGOTIATED_SRVC_AGRMNT.ADS_B_FS} = "T" Then
if mystring <> "" then mystring := mystring + ", ";
MyString := mystring + "ADS");
(If {FD__ADS_NEGOTIATED_SRVC_AGRMNT.ECM_B_FS} = "T" Then
if mystring <> "" then mystring := mystring + ", ";
MyString := mystring + "External Case Manager");
MyString

The first to items are "true" and the last is "False".
Here's what I got: Self, ADSExternal Case Manager

It should have given me: Self, ADS

What am I doing wrong in my formula?
 
I missed out some logic in the first attempt, Try this it should give you the correct results.

Code:
WhilePrintingRecords;

StringVar MyString := "";

(If {FD__ADS_NEGOTIATED_SRVC_AGRMNT.SF_B_FS} = "T" Then MyString := "Self");

(
If {FD__ADS_NEGOTIATED_SRVC_AGRMNT.ADS_B_FS} = "T" Then 
    If mystring <> "" then 
        mystring := mystring + ", ADS"
    Else
        MyString := mystring + "ADS"
);

(
If {FD__ADS_NEGOTIATED_SRVC_AGRMNT.ECM_B_FS} = "T" Then 
    If mystring <> "" then 
        mystring := mystring + ", External Case Manager"
    Else
        MyString := mystring + "External Case Manager"
);

MyString

HTH

Gary Parker
MIS Data Analyst
Manchester, England
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top