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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested If Statement

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am wondering why everthing works in this formula except the Combine.Type = "A" portion at the end. I am able to display the "I" and "P" type values but not the "A" type values. When each IF statement is run separately, they work great. But in a nested IF statement, the last one does not work. Help! I am at my wits end!

Here is the code:

if {Combined.Type} <> &quot;P&quot; then

(if {Combined.Type} = &quot;I&quot; and
date(2000,10,01) >= Maximum ({@Tran Date}, {@Service Number})
and date(2000,10,01) <= Maximum ({@paid date}, {@Service Number}) or
(date(2000,10,31) >= Maximum ({@Tran Date}, {@Service Number}) and
date(2000,10,31) <= Maximum ({@paid date}, {@Service Number})) or
(date(2000,10,01) >= Maximum ({@Tran Date}, {@Service Number})
and date(0000,00,00) = Maximum ({@paid date}, {@Service Number}))
then ({@Invoice}))

else (if {Combined.Type} <> &quot;I&quot; then
(if ({Combined.Type} = &quot;P&quot; and
(date(2000,10,01) >= {@paid date}) and (date(2000,10,31) <= {@paid date}))
or (Maximum ({@paid date}, {@Service Number}) >= {@paid date})
then {@Payment}

else
(if ({Combined.Type} = &quot;A&quot; and
(date(2000,10,01) >= {@Adj Date}) and (date(2000,10,31) <= {@Adj Date}))
or (Maximum ({@paid date}, {@Service Number}) >= {@Adj Date})
then {@Adjustments})))
 
Is the line:

if {Combined.Type} = &quot;I&quot;

supposed to apply to all three pairs of date criteria that follow or just the first pair. The way it is currently written the second and third pairs wouldn't have to be &quot;I&quot; but could be your &quot;A&quot; records. If they are falling into these lines they won't show up later.

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
The first line of {Combined Type = &quot;I&quot;) does not need to be there. I added that because someone said I could create a nested if. The line could be &quot;if not isnull {Combined.Type) then&quot;. I just need the item to go thru the three choices and display the appropriate amount if it is either &quot;A&quot;, &quot;P&quot;, or &quot;I&quot; type. I need to finish this tonight for the customer and I am at a loss!

Thanks for the response. HELP
 
Well, I think it would need the &quot;I&quot; to be there, or else all of your &quot;A&quot; records will qualify for the first group, because they are not &quot;P&quot;. But, I don't know if that is the way you intended it.

The first pair of date rules is currently limited to &quot;I&quot; records, but the second and third pair can be anything that isn't &quot;P&quot; because of the way your parens are set up. Is that intentional? I think your &quot;A&quot; records are falling into this first group. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Thanks for the resonse. I have changed the formula to be as follows and the &quot;A&quot; and &quot;P&quot; types now appear but they appear in every column when they are supposed to fall under only October 2000 and forward.

October 2000 (Detail Line)

if {Combined.Type} = &quot;I&quot; then {@Oct00Type I}
else
(if ({Combined.Type}) = &quot;P&quot; then {@Oct00Type P}
else (if ({Combined.Type}) = &quot;A&quot; then {@Oct00Type A}))



Oct00Type A

(if ({Combined.Type} = &quot;A&quot; and
(date(2000,10,01) >= {@Adj Date}) and (date(2000,10,31) <= {@Adj Date}))
or (Maximum ({@paid date}, {@Service Number}) >= {@Adj Date})
then {@Adjustments})


Oct00Type I

(if {Combined.Type} = &quot;I&quot; and
date(2000,10,01) >= Maximum ({@Tran Date}, {@Service Number})
and date(2000,10,01) <= Maximum ({@paid date}, {@Service Number}) or
(date(2000,10,31) >= Maximum ({@Tran Date}, {@Service Number}) and
date(2000,10,31) <= Maximum ({@paid date}, {@Service Number})) or
(date(2000,10,01) >= Maximum ({@Tran Date}, {@Service Number})
and date(0000,00,00) = Maximum ({@paid date}, {@Service Number}))
then ({@Invoice}) )


Oct00Type P

(if ({Combined.Type} = &quot;P&quot; and
(date(2000,10,01) >= {@paid date}) and (date(2000,10,31) <= {@paid date}))
or (Maximum ({@paid date}, {@Service Number}) >= {@paid date})
then {@Payment})
 
if {Combined.Type} <> &quot;P&quot; then
(
if {Combined.Type} = &quot;I&quot; and
date(2000,10,01) >= Maximum ({@Tran Date},{@Service
Number}) and
date(2000,10,01) <= Maximum ({@paid date}, {@Service
Number}) or
( date(2000,10,31) >= Maximum ({@Tran Date}, {@Service
Number}) and
date(2000,10,31) <= Maximum ({@paid date}, {@Service
Number})
) or
( date(2000,10,01) >= Maximum ({@Tran Date}, {@Service
Number}) and
date(0000,00,00) = Maximum ({@paid date}, {@Service
Number})
)
then
({@Invoice})
)

else
(
if {Combined.Type} <> &quot;I&quot; then
(
if ({Combined.Type} = &quot;P&quot; and
(date(2000,10,01) >= {@paid date}) and
(date(2000,10,31) <= {@paid date})) or
(Maximum ({@paid date}, {@Service Number}) >=
{@paid date})
then
{@Payment}
else
(
if ({Combined.Type} = &quot;A&quot; and
(date(2000,10,01) >= {@Adj Date}) and
(date(2000,10,31) <= {@Adj Date})) or
(Maximum ({@paid date}, {@Service Number}) >=
{@Adj Date})
then
{@Adjustments}
)
)
) //I think there is one too many Brackets here


the reason that TYPE = &quot;A&quot; doesn't work is that it is being trapped in the first Nested if....

IE: if {Combined.Type} <> &quot;P&quot; then


rather than nest them like this it would be better to make them separate and have the result assigned to a variable that is displayed at the end.

I would do your formula this way

WhilePrintingRecords;
NumberVar Result := -999999999 //a ridiculous number since
//zero might be real
//case Type = &quot;I&quot;
if {
Combined.Type} = &quot;I&quot; and
date(2000,10,01) >= Maximum ({@Tran Date},{@Service
Number}) and
date(2000,10,01) <= Maximum ({@paid date}, {@Service
Number})
) or
(
date(2000,10,31) >= Maximum ({@Tran Date}, {@Service
Number}) and
date(2000,10,31) <= Maximum ({@paid date}, {@Service
Number})
) or
(
date(2000,10,01) >= Maximum ({@Tran Date}, {@Service
Number}) and
date(0000,00,00) = Maximum ({@paid date}, {@Service
Number})
)
then result := {@Invoice};

//Case TYPE = P

if (
{Combined.Type} = &quot;P&quot; and
(date(2000,10,01) >= {@paid date}) and
(date(2000,10,31) <= {@paid date})
) or
Maximum ({@paid date}, {@Service Number}) >=
{@paid date}
then result := {@Payment};

//Case TYPE = A

if (
{Combined.Type} = &quot;A&quot; and
(date(2000,10,01) >= {@Adj Date}) and
(date(2000,10,31) <= {@Adj Date})
) or
Maximum ({@paid date},{@Service Number}) >= {@Adj Date}
then result := {@Adjustments};

result;

I do have some concern about these If blocks though I think I have reproduced them faithfully...

for example I think for Type = A it should be written like this

if Combined.Type} = &quot;A&quot; and
(
(
(date(2000,10,01) >= {@Adj Date}) and
(date(2000,10,31) <= {@Adj Date})
)or
Maximum ({@paid date},{@Service Number}) >= {@Adj Date}
)
then result := {@Adjustments};

Same for the others....this way the conditions are exclusively Type &quot;A&quot;...but perhaps this is not the intent.

Hope this helps

Jim Broadbent
 
piazzab,

Sorry, I have no idea what you mean by &quot;in every column&quot;. Each formula is its own column. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top