A number of functions return sets. Click the links below for further details. These are described in the following parts of the documentations.
a Function
The function a returns a set consisting of all possible codes on a question (i.e. the codes of all items in the answer list).
a(qID)Note: There is a limitation with this function when qid uses a table lookup for its answerlist. In this case, it should not be called from the code mask of qid. The workaround is to add an additional hidden single question which points to the same table lookup, and use that with the a() call instead. So if qid1 uses table lookup answerlist and needs to call a(qid1) in its code mask, instead it should use a(qid2) where qid2 is a hidden single question that uses the same table lookup answerlist.
set nset and nnset
There are three functions you can use to define sets with specific codes – set, nset and nnset.
set(code1,code2,...,coden)will return a set consisting of the codes listed within the parenthesis. For example
set("1","3","4")returns a set consisting of the codes "1","3" and "4".
nset(n)will return a set with codes "1","2",...,n. n must be an integer greater than 0. For example
nset(5)returns a set consisting of the codes "1","2","3","4" and "5".
nnset(m,n)will return a set consisting of codes from m to n inclusive, i.e. m,m+1,...,n-1,n. For example
nnset(6,10)returns a set consisting of the codes "6","7","8","9" and "10".
Iset
lset(params)
lset can be used to construct a set. The input to the function can either be an object such as an Array, or a list of parameters from which the function will create a set.
lset(new Array(1,2,8))returns a set consisting of the codes 1, 2 and 8.
Filter Function
The function Filter is used to filter a list based on the matches a prefix has in the answer list.
Filter(qID,prefix)
It returns a set with the codes of items in the answer list of question qID that starts with the string prefix, regardless of case. If prefix is "c", Filter will return the codes of the answers "Cadillac", "Chevrolet" and "Chrysler" if they are in the answer list of qID.
Filtering an Answer List by the First Characters in the Answer
There may be situations where you have a single question with a long answer list, which you want to filter based on text input by the respondents. In this case you can present an open text question to the respondents asking them to provide the first one or two letters in their answer, and then filter the answer list based on that answer.
For example, imagine you have a single question carmake where the respondent is to be asked to select a car make from a list. There are a lot of different car makes, so the selection list will be long. Here you can place an open text question prefix in front of the car question. In the prefix question the respondent is asked to type in the first letter in the name of the car, and this will filter the answer list such that only those car makes starting with the input letter will be presented. The code mask of the car question can have this code mask:
Filter("carmake",f("prefix").get())
f Function
The f function can also be used in set context (code and scale masks). The f function does not return a Set object, but a form object. However, since it can be used in set context (in code and scale masks) and has most of the methods of the Set object, we choose to discuss it together with the Set object. The two set methods not supported by the form object are add and remove.
f(qID {,loopiter1,loopiter2,...,loopitern})The curly brackets {} are used here to indicate that the loop iterations are optional arguments (go to About the f Function for more information).