Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Page layout facilities > Styles > Dealing with dates
 
Dealing with dates
Forms often require users to enter or select dates or partial dates. Typical examples are dates of birth or start and end dates for credit cards or club membership. Depending on how you want to use the data, you can either display a simple input box and let respondents enter a value of their choice, or you can present the question with separate boxes for each date part. The easiest way to display separate boxes for each date part is to create a separate question with a drop-down response list for each date part you want, and to display the questions and response controls side by side in a single line. Here’s an example that prompts for the user’s date of birth:
Date of birth a 3 side-by-side drop-down lists
This graphic is described in the surrounding text.
It was created using the following routing code:
' Template for question text & response controls on same line.
IOM.Questions[..].QuestionTemplate = "styles2.htm"
' Response box on same line as question text
Dayname.Style.ElementAlign = ElementAlignments.eaRight
Monthname.Style.ElementAlign = ElementAlignments.eaRight
Yearnumber.Style.ElementAlign = ElementAlignments.eaRight
' Question text on same line as previous response box
Monthname.Label.Style.ElementAlign = ElementAlignments.eaRight
Yearnumber.Label.Style.ElementAlign = ElementAlignments.eaRight
' Drop-down response lists
DayName.Style.Control.Type = ControlTypes.ctDropList
MonthName.Style.Control.Type = ControlTypes.ctDropList
YearNumber.Style.Control.Type = ControlTypes.ctDropList
Dob.ask()
The questions were defined as basic categorical questions, with MonthName and YearNumber having null question texts since these were not required in the form.
Here’s the same specification defined entirely in the metadata section:
DayName1 "Date of Birth" labelstyle(elementalign="right")
style(elementalign="right", control(type="droplist"))
categorical[1..1]
{
d1 "01",
d2 "02",
d3 "03"
};
MonthName1 "" labelstyle(elementalign="right")
style(elementalign="right", control(type="droplist"))
categorical[1..1]
{
January, February, March, April, May, June, July,
August,September, October, November, December
};
YearNumber1 "" labelstyle(elementalign="right")
style(elementalign="right", control(type="droplist"))
categorical[1..1]
{
y1956 "1956",
y1957 "1957",
y1958 "1958"
};
Dob1 "" page (DayName1, MonthName1, YearNumber1);
This example uses the question sub-template shown earlier in this topic.
Using tables to simplify alignment specifications
Some forms are precisely laid out so that the overall effect of the form is grid-like; that is to say, the question texts and response controls in each row line up with the corresponding elements in the other rows. If this is the layout you want for your form, a template that lays out the elements as a table might help to simplify the alignment specifications.
Example
The DDL comes with an example project that illustrates this perfectly. It is in the [INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\\Scripts\Interview\Projects\Forms folder. The questionnaire file contains two examples, and it is the second one that uses a tabular layout. The form looks like this:
This graphic is described in the surrounding text.
The question texts appear above the response boxes and all the boxes are lined up under one another. The template for the form (TableForm.htm) defines a table of three rows of four columns each. Questions 1 to 4 go in the first row, questions 5 to 8 go in the second row, and questions 9 to 12 go in the third row.
This template does not specify the locations of the question texts and response controls, so you would expect each table cell to contain one question displayed using the default layout; that is, a question text and a response control on separate lines with a blank line in between. However, in the illustration, there are no blank lines between question texts and response boxes. This is because each question contains the specification style(ElementAlign="NewLine") which instructs the interviewing program to insert a line break between the question text and the response control. The indentation of the response boxes is the standard indentation used to separate the response box from the question text, and is not specified in the script.
See also
Alignment and positioning
Interview scripting