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

if then else statements

Status
Not open for further replies.

harding1031

Programmer
Oct 21, 2004
65
US
1. if Left({IMITREP.SCEOA},3) = 'REC'
2. then total_capacity := recycle_capacity * 24
3. calculated_rate := holdweight1/total_capacity
4. else if Left({IMITREP.SCEOA},2) = 'LO'
then total_capacity := recycle_capacity * 24
else if Left({IMITREP.SCEOA},3) = 'BND'
then total_capacity := blend_capacity * 24;

Crystal 9.0
I am getting an error when I have more than two statements after "then", are we only allowed one statement in the "then" clause? The statement in line 3 is valid when it is not part of the "if" statement and the "if" statement works fine when I remove line 3.. Any ideas. TIA.
 
I am not sure why you are using variables, and I assume you have declared them elsewhere in the report. If not let meknow, but in the meantime try this:

Code:
WhilePrintingRecords;
if Left({IMITREP.SCEOA},3) = 'REC'
then total_capacity := recycle_capacity * 24;
calculated_rate := holdweight1/total_capacity;
    else if Left({IMITREP.SCEOA},2) = 'LO'
        then total_capacity := recycle_capacity * 24
        else if Left({IMITREP.SCEOA},3) = 'BND'
             then total_capacity := blend_capacity * 24;

Not the additional semicolons and the WhilePrintingRecords evaluation time.

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
askdon@srhconsulting.com
 
I think you would also need to add parens around the multiple clauses in dgillz's solution:

WhilePrintingRecords;
<variable declarations here>


if Left({IMITREP.SCEOA},3) = 'REC' then
(
total_capacity := recycle_capacity * 24;
calculated_rate := holdweight1/total_capacity;
) else
if Left({IMITREP.SCEOA},2) = 'LO' then
total_capacity := recycle_capacity * 24 else
if Left({IMITREP.SCEOA},3) = 'BND' then
total_capacity := blend_capacity * 24;

-LB


 
Thanks guys, I guess I was bit unclear because of my sample code. I really needed to know how would I format an if then else statment when there were more than one executable statements for the then clause. It appears that I have to put the statements in paren.
if...
then (statement 1;
statement 2)
else...

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top