Cache( fails when embedded within ?(

The cache( function fails in this specific use:

?(cache("DataValue", "cVALUE") = "TestValue", "FAIL", cVALUE)

In real life, “DataValue” is a formula, but the above simplification fails in my environment, both in a procedure, a field or the Formula Workshop.

Does anyone else see this behavior?

To get your text example to work I had to add “” to the temporary variable value:

?(cache("DataValue", "cVALUE")="TestValue","FAIL",cVALUE+"")

And to work with a numeric value I had to add a 0 to the value:

?(cache(25, "cVALUE")="TestValue","FAIL",cVALUE+0)

Why??? Don’t have a clue. :face_with_spiral_eyes:

Gary, that rang a bell for me! I checked my notes and thereby found the reference in the Panorama X help file by searching for “empty string” as a full text search:

“As a general rule, this technique is necessary whenever you wish to use a variable to store the name of a field passed as a parameter to a statement or function in which the field name parameter may be either quoted or unquoted. These include the datavalue(, fieldformula(, fieldnumber(, fieldpattern(, fieldwidth(, getfieldproperties( and grabfieldtype( functions, and the dozen or so lookup( functions whose parameters include a field name.”

Those functions … datavalue(, fieldformula(, etc … all have the same notification. The ?( function needs to be added to that list.

I had forgotten that little “trick.” Thank you, Gary!

This only seems to be true when using the cache( function with the ?( function. Any other existing variable used the same way does not require this “trick”.

I suspect the problem is that when the variable name is used alone, it is calculated immediately – before the variable has actually been defined. Panorama has a special case for when a function parameter consists of nothing but a single operand – for speed it just uses the value rather than actually processing the formula. Normally that is fine, but it doesn’t allow for the fact that the cache( function can modify subsequent parameter values.

Is this a bug? Maybe. On the other hand, I don’t think there is any place in the Panorama documentation that states that function parameters are evaluated from left to right. Your code is assuming that is the case.

Here’s another way to write the formula that does work. This version makes sure that cValue is fully defined before the ?( function is evaluated. I think this is a better approach than relying on the quirk that the order of parameter evaluation is different depending on whether the parameter is a single operand or a more complex formula.


Note that this issue is completely different than the other cases where +"" is used, at least as far as Panorama’s internal code goes.

Basicallly, I would recommend avoiding use of the cache( function within any function with multiple parameters, not just the ?( function.



Thank you for the “improved” way to use cache and the ?( function. I also appreciate the detailed background explanation.