Question
This may be a general question of nested variable expansion, but I haven't found an answer yet (although there are topics which discuss related issues with CALC and SEARCH). I would like to use the
SpreadSheetPlugin to calculate new values for form elements. In order to do this, I need to retrieve the current value, which can be done with URLPARAM. Unfortunately, I cannot seem to find a way to embed the URLPARAM expansion into a CALC. For example, suppose I want a button on a calendar page that will go to the month previous to that shown. What I want is a formula like this:
%CALC{"$IF(%URLPARAM{"month"}% == 1,12,$EVAL(%URLPARAM{"month"}%-1))"}%
So that I end up with, if month currently equals 2:
%CALC{"$IF(2 == 1,12,$EVAL(2-1))"}%
Yielding a result of 1.
However, what I get is: ERROR: syntax error, near "=="
I'm confident TWiki has a way to accomplish this. Can someone enlighten me?
--
DavidBright - 18 Feb 2005
Environment
--
DavidBright - 18 Feb 2005
Answer
Not an answer, just an idea, but does the situation improve if you use a Set to assign the value of the URLPARAM to a local variable before the line containing your CALC?
I suspect this is a problem with the tag parser, and by "easing the load" it may suddenly work.
--
CrawfordCurrie - 20 Feb 2005
Thanks for the pointer,
Crawford. At first it didn't work, but I spent more time on it and realized that the URLPARAM was blank on the first call, so the == test was trying to compare blank with a number. That was the error. In the end, though, I ended up using some separate $SETs and calculations just to make it easier to follow. Here is what I ended up with:
%CALC{"$SET(month, %URLPARAM{"month"}%)"}%
%CALC{"$IF($EXACT($GET(month),), $SET(month, $FORMATTIME($TODAY(), $month)),)"}%
%CALC{"$IF($GET(month) == 1, $SET(pmonth, 12),$SET(pmonth, $EVAL($GET(month)-1)))"}%
There are similar calculations for the year, of course, but this should give you the idea.
We can mark this one answered. Thanks again!
--
DavidBright - 21 Feb 2005