Use of macros within enablements

I have a macro for working age($workingage) in a my survey and I use it to enable sub sections. I have tried to use the same macro along with with a sex/gender question to enable a “Union Status” question: $workingage && DEM_SEX == 2 (2=Female) and it the question is enabled for both sexes.

Can I use the macro in this way or should I simple use my age and sex variable in the my union status enablement?

Neville

You may use macros for any enabling condition. It work as a placeholder to inject the value of the macro into expression. You may write down an expression and then extract it into macro to use it later again.
Unfortunately you didn’t provide the value of your macro so it’s hard to say what is wrong.
Here is an article about macros https://support.mysurvey.solutions/questionnaire-designer/toolbar/macros/

Thanks Vitalii

So my macro uses
DEM_AGE.InRange(15,115) || DEM_AGE==150

Where DEM_AGE a variable calculated from based on either full years from a year or birth or if the either give a age at last birthday or the DEM_AGE of 150 being a special value for persons over 15 years.

I have used the( DEM_AGE >14 && DEM_SEX==2) instead of the macro and it works as expected, I wouldn’t create a macro for this instance as the I would only use this macro for one question. I thought it would evaluate fine.

So the way you may go is to adjust your expression to work correctly and then extract it to the macro.
You may extract any part of expression to the macro.
So if you have expression looks lie that
expression: (DEM_AGE.InRange(15,115) || DEM_AGE==150) && DEM_SEX == 2
you may extract it like:
$macro: DEM_AGE.InRange(15,115) || DEM_AGE==150
expression: ($macro) && DEM_SEX == 2

Do not forget about brackets.

The brackets did it, working as expected.

Thanks

I always put my (boolean) expression inside the macro between parentheses.
This way I can refer in a condition to the macro without adding parentheses.
(same effect as you are doing now, but maybe safer, because you don’t have to remember putting parentheses every time you use the macro).