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!

Assign Formula name to Variable

Status
Not open for further replies.

SaintJason

Technical User
Jul 18, 2007
7
Hi,

Is it possible to assign the name of a formula to a variable?

I have 120 formulas which call a function which returns a string.

Each formula name has a number in it's name and I want pass this number to the function.

At the moment each of the 120 formulas uses a unique bit of code e.g.

Name Code

Formula1 Function(1)
Formula2 Function(2) etc.

I want to use the same piece of code in each of the formulas

e.g Function(tonumber(Mid(<formulaname>,8)))

8 being the starting point of the number in the formula name

Please let me know if this is possible to use the formula name.

Thanks














 
The short answer is no.

If someone has a way to do this, I can easily imagine having multiple uses for it, so hopefully someone else will speak up.

When I've had to do the equivalent my code looked about like this:

Code:
shared numbervar array numArrGeneral;
local numbervar numInstance;
numInstance:=
5
;

//Output
numArrGeneral[numInstance];

Where I put a copy of this into every formula required, then when back and changed the hard-coded value of 5 (five) to whatever number was needed for that instance. The 5 is set strangely on the page so it could be highlighted with least difficulty and then changed.

Excruciating. But the only solution I came up with for this.

I'm hoping someone else here has an even better way to approach this kind of problem.



 
Create a "master" function that depends on a global variable to branch into the appropriate code. Then, in your calling formula set that global variable and then call the master function.

- Ido

view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Hi smcnulty2000 & IdoMillet, thanks for your posts.

Good idea about the position of the number, makes it much easier to edit.

IdoMillet, I think in your idea each formula would still to specify a specific value for the global variable. I'm trying to get away from that and just have one identical piece of code for all the formulas.

I think I may have come up with a solution.

I have a formula which delares a numbervar in the report header.

Then each of the 120 formulas has the following code

global numbervar x;

x := x + 1
Function(x)

This seems to work, will give it a thorough test today.

Thought I might be able to get away with having just the one formula on the report multiple times, but this returns a result where x = 1 for all objects.




 
I'm interested but skeptical.
I'm worried that the evaluation time would cause them to all run at the same time.

Interested to hear your results.
 
Hi smcnulty2000.

The evaluation is done in the order the objects were placed in the section (they are all in a report header section)

I'm surprised at this, I was expecting them to be evaluated in relation to their positions from left to right.

A problem occurs if you accidently move an object out of the section and back again, it evaluates it last from then on. Then you have to create a new section and move all of the objects into it one at a time.

For this reason I have decided to hard code the value for each formula.

Would be so great to be able to use a formula name in the formula itself. If you ever find out, please let me know!




 
Umph. Kinda kludgy. I think I'd take the same route.

I would like to see that as well.

I would also like to be able to tell using a function which section the formula is sitting in. I have yet to ask the people at crystal if they'll ever build this but I think they would give some report writers an added bump in functionality that would be worth it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top