Professional > Interview scripting > Writing interview scripts > Repeated questions > Splitting large grids over several pages
 
Splitting large grids over several pages
Large grids can be difficult to display effectively on a single page without resorting to small fonts and cramped row and column spacing. A better approach is to split the grid over a number of pages. This immediately makes it easier for respondents to use and allows you to retain the styles and page layout set in your standard templates.
Start by defining the grid in the metadata section in the usual way. Then place the following statements in the routing section at the point you want to display the grid.
Syntax
Dim start_pos_variable
Dim numrows_variable
start_pos_variable
= 0
numrows_variable = rows_per_page
' QuestionFilter assignment is split across two lines for
' printing purposes only
While (start_pos_variable < loopname.Categories.Count)
  loopname.QuestionFilter =
      loopname.Categories.Mid(start_pos_variable,
      numrows_variable)
  loopname.Ask()
  start_pos_variable = start_pos_variable + numrows_variable
  loopname.QuestionFilter = NULL
End While
Parameters
start_pos_variable
A variable that is used to mark the start position in the loop control list for the current page.
numrows_variable
A variable that stores the number of rows to display on each page.
rows_per_page
The number of rows to display on each page. You must specify this value in the routing section (as in the example below) or ask a question whose value can be used as the value for this parameter.
Example
Here’s an example that will make understanding this general syntax much easier. The grid is defined in the metadata section as follows:
LargeGrid "For which of the following insurance companies have
you seen or heard advertising during the three months?" loop
{
RedWhiteBlue "Red, White, Blue Insurance",
InsuranceToGo "Insurance To Go",
WhistleHope "Whistle and Hope",
BestDeals "Best Deals",
CloverBenCo "Clover Ben and Co",
Rothwood,
Woodhurst "Woodhurst Ltd",
TusonNoakes "Tuson, Noakes and Partners",
GoFaster "Go Faster",
BestDealsFaster "Best Deals Faster"
} fields (
SeeHearAds "SeeHearAds" categorical [0..]
{
Seen "Saw advertising",
Heard "Heard advertising"
};
) expand;
The routing statements that split this grid so that only five rows are displayed on each page is:
Dim startpos
Dim numrows
startpos = 0
numrows = 5
While (startpos < LargeGrid.Categories.Count)
LargeGrid.QuestionFilter = _
LargeGrid.Categories.Mid(startpos, numrows)
LargeGrid.Ask()
startpos = startpos + numrows
LargeGrid.QuestionFilter = NULL
End While
The While loop in this code is repeated all the time that the current start position in the loop control list (startpos) is less than the total number of items in the loop control list (LargeGrid.Categories.Count). It filters the loop control list by selecting five items starting at the current start position, and then displays a grid containing the repeated questions and those five items. When the respondent clicks Next, the new start position is calculated by adding five (numrows) to its current setting.
The last statement inside the loop resets the filter to null so that all items in the loop control list will be eligible for inclusion in the grid when the loop is repeated. The fact that the start position has changed means that those items that have already appeared in the grid will be skipped, so there will be no duplication of items. If you omit this statement the loop will be repeated once only because, as far as the interviewing program is concerned, all items were used in the first repetition: the fact that filtering excluded most of them is irrelevant.
See also
Repeated questions