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

Passing a variable to an @function

Status
Not open for further replies.

jabruno

MIS
Apr 4, 2001
20
0
0
US
I am having a brain fart.

Is it possible to pass a variable to a function?

For example, I would like to create a function where I can pass a number, or variable from a DB that will be divided by 10. The Function would be accessed by:

@DivideByTen(100)

This Function would then return 10.

It seems to me that I would have to create a seperate function for each field in a database that I would want to run in this function by placing it in a shared variable. I would prefer a more direct approach.

Thanks In Advance


 
Functions and variables only exist in formula fields.
You can simply create a formula that is:

{field} / 10

and wouldn't need functions or variables.
You would need one formula for each field that you wanted to adjust. Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
Thanks Ken,

The actual formula that I will be using more complex. The example was just a gross simplification.

But, you did answer my question. I can't pass a variable into a function.

Thanks for the response.

Jim
 
I am not sure about that.
You can create functions if you want to write them and compile the DLL yourself.
You decide what arguments the function will require.
Most arguments can be a field or a literal or a variable.

However, all of this requires a formula. Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
CERTAINLY YOU CAN PASS A VARIABLE INTO A FORMULA - you just have to define your problem better for Ken or I to answer it

Several ways to do it.

1. pass a user entered parameter into the report (perhaps defaulted to be = 1 so in general no division takes place)


numberVar Result;
stringVar Warning := "";

[complicated calculation yielding "Result"]

if {?parameter} <> 0 then
Result := Result/{?parameter}
else
(Result := 0;
Warning := &quot;Division by zero error&quot;);
Result;

2. Pass a variable calculated by another formula into another formula

Here you must specify the evaluation sequence to be sure it is done right.
*************************************************
Formula 1

NumberVar result1;
NumberVar form_result1;

{complicated calculation yielding result1 + form_result1]

form_result1;
*************************************************

BUT YOU WANT THE calculated result1 value to use in another formula (formula 2)

*************************************************
Formula 2

evaluateafter(@Formula1) // this is vital to calc order
NumberVar result1;
numberVar final_result;

{complicated calculation using result1 to calc final_result]

final_result;
*************************************************


those are 2 possiblities....more may be possible...but if you want a concrete answer ... you must give an example that reflects the complexity...please

Hope this helps

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top