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

How to use for loop in a formula?

Status
Not open for further replies.

foru11

MIS
Aug 25, 2011
38
MY
Hi All,

I am using CR 10, Oracle 11g.

I would like to get a data field from the table but it doesn't seem working. User is allow to select more than 1 record to print at the report.

Here is my formula:

numbervar i;
numbervar cnt := recordnumber;
stringvar str;

for i := 1 to cnt do
(
if not isnull({SALES_QUOTATIONS.REMARK}) then
(
str := {SALES_QUOTATIONS.REMARK};
exit for;
)
);
str

The field Remark not necessary will have data but if 1 of the records is having data for this field, it has to show in the report.

Thanks in advanced for any help.
 
I think your formula should be modified as below. However not sure what you are trying to do with the cnt variable. Recordnumber just returns the record number NOT the total number of records

numbervar i;
numbervar cnt := recordnumber; // Not sure wht this is doing
stringvar str;

for i = 1 to cnt do // you had i:= 1 which is assigning a value not testing
(
if not isnull({SALES_QUOTATIONS.REMARK}) then
//( no need for brackets
str := {SALES_QUOTATIONS.REMARK};
//exit; for I have never used Exit so don't think this is correct crystal syntax

//)
);
str

Ian

 
Hi Ian,

Thanks for replying.

Actually I need to get the total record number to do the loop. I thought the recordnumber will have the total record count. My mistake. May I know how can I get the total record count?

I will have a test at your suggestion after I get the total record count.

Thanks again.
 
Use

numbervar cnt := count({SALES_QUOTATIONS.REMARK});

This will return count for whole report if you are doing this within a group

numbervar cnt := count({SALES_QUOTATIONS.REMARK}, {what ever is your groupfield});

You might also need to add

whileprintingrecords; as first line of formula.

Ian
 
Hi Ian,

I have tested using your suggestion but still no remark come out.

Wondering what would be the problem?

Thanks.
 
Place the variable formula in detail section and make it visible, see what is returned with each line.

Also create another formula with just

if not isnull({SALES_QUOTATIONS.REMARK}) then
{SALES_QUOTATIONS.REMARK} else 'NULL'

and see what that returns in detail line

Ian
 
Depending on your version of CR, you may have the option to chose 'Default values for nulls'. This may help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top