IdCode: functions

Compatibility: IdSurvey 6 IdSurvey 7
X

In this article you will learn how to design functions with IdCode programming language.

To write the questionnaire of your survey with IdCode you can:

  • click on “Import from script”, if you’ve just created your survey and it’s the first time you open “Questions” section. If you’re importing a code from version 6 into version 7, please use the “import from IdSurvey 6” button, then proceed normally.
  • click on the gearwheel button of the pages box and then on “IdCode – Display script” if you want to work on the code of the entire questionnaire.
  • click on the “IdCode” button you find on the top part of each page to work on the code of a single page.

CompareDate function

This function compares two dates (example: display the question just if the date of birth is greater than a specific date).

Syntax:

CompareDate (date1,date2) 

It gives back -1 if date1 is inferior (earlier) to date2, 0 if they are equal and 1 if date1 is greater (following) than date2.

Example:

if(CompareDate ([quest1],1970-12-31) ==1)

Display the question just if the date inserted in quest1 is after December 31st 1970

ContainsText function

It checks the presence of a specific text within an open end answer.

Syntax:

ContainsText ([questioncode],’text’)

It gives back 1 if the text searched is present, it gives back 0 if the text searched is not present.

Example:

if(ContainsText ([quest1],'sea')==1)

Display a question just if in the open answer text of quest1 the word ‘sea’ is present

CountCode function

It allows to know the number of selected options in a multiple choice question.

Syntax:

CountCode (questioncode)

It gives back the number of selected options to the question

Example:

if(CountCode (quest1) >=3)

Display the question just if for quest1 3 or more options were selected

CountResponsesWithCode function

It allows to know, in a specific group, the total number of questions that were answered with a specific option.

Syntax:

CountResponsesWithCode (questioncode1,questioncode2,. . ., questioncodeN, Answercode)

It gives back the total number of questions in group questioncode1,questioncode2,. . ., questioncodeN answered with the option ResponsesWithCode

Example:

if(CountResponsesWithCode (quest1,quest2,quest3,quest4,quest5,quest6,99) >= 3)

Display question just if interviewee answered with code 99 at least to 3 of the question in group quest1,quest2,quest3,quest4,quest5,quest6

CountResponsesWithText function

It allows to know the total of questions answered with a specific text in a specific group.

Syntax:

CountResponsesWithText (questioncode1,questioncode2,. . ., questioncodeN,’text to search’)

It gives back the total of questions in group questioncode1,questioncode2,. . ., questioncodeN whose answer contains ‘text to search’

Example:

if(CountResponsesWithText (quest1,quest2,quest3,quest4,quest5,quest6,'mouse') >= 3))

Display question just if interviewee answered with text ‘mouse’ at least to 3 of the question in the group quest1,quest2,quest3,quest4,quest5,quest6

CheckQuota function

It allows to know the total of interviews completed in a specific sampling cell.

Syntax:

CheckQuota (‘quotaname’)

It gives back 1 if the sampling cell with name ‘quotaname’ is closed, 0 if it’s open

Example:

if(CheckQuota ('NorthEast') ==1)

Display the question just if the sampling cell called ‘NorthEast’ is closed

Algebraic expressions

It gives a numerical value from the arithmetical expression that it has as argument.

Algebraic operators allowed are:

  • Sum +
  • Subtraction –
  • Multiplication *
  • Division /
  • Module (or remainder) % (e.g. : 129%60 = 9)

Syntax:

If(….)

Example:

if( ([quest1]*60 + [quest2] + [quest3]*60) /60) > 20)

Display question just if algebraic expression ([quest1]*60 + [quest2] + [quest3]*60)/60 is greater than 20.