In this article
Code masks are used to filter the answer lists of 3D-grids, grids, single, multi, ranking, open text list and numeric list questions, and to select a set of iterations for a loop. In the code mask field in a question's Properties page (go to Question Properties Overview for more information) or in the loop construct (go to About Loops for more information) you may use a Jscript expression that evaluates to a set of codes. The answer list (or loop member list) will be filtered based on the set of codes in the Code mask field.
Scale masks are used to filter the scale lists of grid questions. Use the scale mask field in a grid question's Properties page (go to Question Properties Overview for more information) to enter a Jscript expression that evaluates to a set of codes. The scale list will then be filtered based on this set of codes.
We have already seen how the f function evaluates to a set of codes when used on multi questions.
In the question "Tvchannels", the respondent answered ABC, CNN and NBC (codes 1, 3 and 5.). In the next questions only these should appear. So in the code mask field of questions "rank" and "hours", the following expression was used: f("Tvchannels"). This expression gave a set with the codes 1, 3 and 5 and consequently only the items in the answer list matching those codes were displayed.
a qID
a("qID") returns the complete set of codes defined in the answer list belonging to qID, irrespective of whether or not they are answered.
set nset nnset
You may need to create sets yourself. The three functions described below should simplify this process.
- set("code","code",…) returns a set consisting of the codes you specify. set("1","2","3") gives the set consisting of the codes 1, 2 and 3.
- nset(n) returns a set populated with the members 1, 2, 3,…,n. nset(3) gives the same as the previous example, a set consisiting of the codes 1,2 and 3.
- nnset(m,n) returns a set with values from m to n: m, m+1,…, n-1, n. So nnset(4,6) gives a set consisting of the codes 4, 5 and 6.
Example: You use a general predefined list as your answer alternatives in several questions, but in a particular question you only want to return answer alternatives 8,9,10,11 and 12. Then all you have to do is to put nnset(8,12) in the Code mask property of that question.
union
f('Q1').union(f('Q2')) returns a new set that is the union of f('Q1') and f('Q2'), that is a set consisting of all codes answered to either Q1 or Q2. If you want to add specific codes to a set in a code mask, then use .union() in combination with set().
Figure 1 - Example: f(‘qID’).union(set(‘99’)) Here you will always include the answer alternative with code ‘99’
isect
f('Q1').isect(f('Q2')) returns a new set that is the intersection of f('Q1') and f('Q2'), that is a set consisting of all codes answered both in Q1 and Q2.
diff
f('Q1').diff(f('Q2')) returns a new set that is the difference between f('Q1') and f('Q2'), that is a set consisting of all codes answered in Q1 and not in Q2. If you want to remove specific codes from a set in a code mask, then use .diff() together with set()
Figure 2 - Example: f(‘qID’).diff(set(‘1’)) Here ‘1’ is never included.
Codes
Remember that the code mask gives a set of codes that are used to filter the answer list/iterations. Make sure that you use exactly the same codes on the items of the answer lists in the different answer lists, or else the masks will be wrong. Tip: Use Predefined scales/lists (go to Adding New Objects to the Survey Tree for more information) as much as possible when using code masks, because then you are sure that the codes are exactly the same in the different questions.