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!

!! Passing a parameter to a formula !!

Status
Not open for further replies.

ipazzo

Programmer
Jan 17, 2002
69
IT
HI, all.

How can i call a formula in another formula passing a parameter.
eg:

formula1:
x = formula2(1)
y = formula2(2)


formula2:
formula2(n)
ret = some calculation with (n)
return ret
 
What portion of that is a parameter?

You can reference parameters in formulas as in the following.

Return a single descrete value:

{?parm1}

Return the first value in a multi value parameter:

{?parm1}[1]

Display all of the values selected in a multi value parameter, delimited by a comma:

join({?parm1},", ")

Iterate through the values of a multi value parameter:

whileprintingrecords;
numbervar counter :=0;
stringvar Result := "";

for counter := 1 to ubound({?parm1}) do(
if {?grp}[counter] = "US" then
Result := "US was chosen"
);
Result

The above would return "US was chosen" if any of the values = "US"

Any of the above can be referenced within formulas.

Hope this resolves. If not, provide example data, and expected output, someone can probably provide a more tailored solution.

-k
 
Thanks, for tour reply.

What i need is to call a formula from another formula passing a value from the calling formula to the called formula.

in my example formula1 is the calling formula

formula2 is the called formula

in formula1 i call formula2 passing a value of "1" the first time and passing a value of "2" the second time.

Ciao!
 
Check the evaluateafter function.

You can reference a formula within another formula, as in:

@formula1
{table.field} / 100

@formula2
evaluateafter(@firmula1)
@formula1 * 100

In this case you've used formula1 as a value in formula2

The alternative is to use a shared variable, as in:

@formula1
shared numbervar PassNum1;
shared numbervar PassNum2;
PassNum1 := {table.field} / 100
PassNum2 := {table.field} / 50

@formula2
shared numbervar PassNum1;
shared numbervar PassNum2;
Passnum1 + Passnum2

In this case you reference variables built by another formula.

If this doesn't resolve, please provide sample data and expected output rather than text, it's hard to discern your needs from generic questions like this.

-k
 
ERROR:
"The Remaining Text does not appear to be part of the formula"

these are my formulas:

xSz:
shared stringvar pSz;
IIF(IsNumeric(pSz),IIF(instr(pSz,".")>0,left(pSz,instrrev(pSz,"."))+1,pSz),pSz)

1Sz:
shared stringvar pSz;
pSz := {SIZE_.SIZE1}
@xSz

2Sz:
shared stringvar pSz;
pSz := {SIZE_.SIZE2}
@xSz

3Sz:
shared stringvar pSz;
pSz := {SIZE_.SIZE3}
@xSz
 
Well, first of all....you are not passing Parameters in the CRYSTAL sense of the word. Parameters are user input...here you are just passing a variable value.

There are some syntax errors in your formulas.

First of all, You don't need the variables to be "shared" as you are not passing them to a subreport

Second...I don't use IIF that much....Use of IFF seems right from a VB perspective but can be tricky in Crystal....I will suggest an alternative.

@xSz (this would not be placed on the actual report)
stringvar pSz;
if IsNumeric(pSz) then
(
if (instr(pSz,".") > 0 then
left(pSz,instr(pSz,".")-1)
else
pSz;
)
else
pSz;

*************
I have never used instrrev but I think there is a syntax error in what you wrote

IIF(instr(pSz,".")>0,left(pSz,instrrev(pSz,"."))+1,pSz)

should be

IIF(instr(pSz,".")>0,left(pSz,instrrev(pSz,".")+1),pSz),

*************


Now your other formulas would be....NOTE the additonal semicolons

1Sz:
stringvar pSz;
pSz := {SIZE_.SIZE1};
@xSz;

2Sz:
stringvar pSz;
pSz := {SIZE_.SIZE2};
@xSz;

3Sz:
stringvar pSz;
pSz := {SIZE_.SIZE3};
@xSz;

this should work now Jim Broadbent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top