Navigation:  Macros > Macro Language > Built-in Functions > All Functions (Alphabetical) >


Previous pageReturn to chapter overviewNext page

str = EvalToken(nDate,sToken)


This macro function returns the value that a token sToken (or a string containing one or more tokens) will have on the date nDate.


sCurMonthName = EvalToken(Today(),'[Mmmm]')


This function does not limit you to the evaluation of a single token. The following example would also work as expected :


sCurMonthName = EvalToken(Today(),'The date is [Mmmm] [d]')


Note that if, at the end of a macro, sRESULT includes any tokens, they will be evaluated automatically, assuming the same DayValue and LanguageTag as those of the incoming macro token.


There are thus 2 main reasons to make the effort of evaluating a token yourself, within a macro, using the EvalToken function :


You need the token to be evaluated with a different DayValue or LanguageTag. But in that case the token passed to sRESULT can be modified, using s_TokenRoot, to have the desired DayValue and/or LanguageTag.


 sRESULT = '[' + sNewLanguageTag         ->

                               + IntToStr(nNewDayValue)  ->

                               + s_TokenRoot + ']'


You need to "see" the result of the token evaluation within the macro code to then branch or loop in the code accordingly (though in this case you might wish to use the function PeekTokenValue instead).


Precautions to use when using this function :


Make sure you include the token's braces (actually, if there are no braces in sToken, then Q++ will automatically add braces to the fron and back).

If the token involves holidays, make sure that you have used the functions SetCurHolidaysList and FindHolidayOnDate to initialize the holidays table.


Note that this function will generate all the same side-effects as if the token(s) it evaluates were part of a template. For example, if the token being evaluated is a Moon phase token, then code will be generated to change the result of the macro to the appropriate Moon phase symbol. If you are just calling this function to see what the result would be, then you should use the function PeekTokenValue instead, which discards any side-effects encountered during the evaluation of tokens.


See also: PeekTokenValue.

Topic 105097 updated on 21-Jul-2017.
Topic URL: http://www.qppstudio.net/webhelp/index.html?evaltoken.htm