Comparison of rollbacks to save points and rollbacks using GoTo
This topic contains some scripts that illustrate how rolling back to save points works and compare this approach with using GoTo. The metadata for both examples is as follows:
TotalCost "What was the total cost of the meal that you had
when you left the cinema?" long [1..500];
Food "How much of that was for food?" long [1..500];
HadDrinks "Did you have drinks with the meal?" categorical [1..1]
{Yes, No};
Drinks "How much did you spend on drinks?" long [1..500];
Service "And how much went on service/tips?" long [1..500];
NoMatch "The sum of the costs for food, drinks and service does not
match the total. Your answers were:<br/>
Total cost {#TotalCost}
Food cost {#Food}
Drinks cost {#Drinks}
Service cost {#Service}<br/>
Please try again." info;
Summary "These are your answers
Total cost {#TotalCost}
Food cost {#Food}
Drinks cost {#Drinks}
Service cost {#Service}" info;
Using save points
The routing for the version that uses save points is:
Dim sum
TotalCost.Ask()
Food.Ask()
sum = Food
HadDrinks.Ask()
If (HadDrinks="Yes") Then
Drinks.Ask()
sum = sum + Drinks
End If
Service.Ask()
sum = sum + Service
If (sum <> TotalCost) Then
NoMatch.Show()
IOM.SavePoints["TotalCost"].Go()
End If
Summary.show()
Assume that a respondent gives the following answers:
Parameter
|
Answer
|
TotalCost
|
100
|
Food
|
70
|
HadDrinks
|
Yes
|
Drinks
|
25
|
Service
|
10
|
The sum of the three values (105) exceeds the total cost so the respondent is asked to correct their answers. The script goes back to the save point for
TotalCost which, in this case, is at the start of the script, and resets the answers to any questions and temporary variables between this point and the previous position in the script to their initial unanswered state. This ensures that any questions or variables that become off-path due to changed answers will have no value. When the value of an off-path question is checked in script, its value will be empty. However, as each question is asked again, the previous answer, or off-path response, will be displayed. If the off-path response also needs to be cleared, the
ClearOffPathResponse method can be used. For more information, see
Dealing with off-path data.
Using GoTo
Now here’s the same routing section written using GoTo:
Dim sum
Dim times_asked
GoHere:
times_asked = times_asked+1
TotalCost.Ask()
Food.Ask()
sum = Food
HadDrinks.Ask()
If (HadDrinks="Yes") Then
Drinks.Ask()
sum = sum + Drinks
End If
Service.Ask()
sum = sum + Service
' This stops the script getting into an infinite loop
If (times_asked>2) Then
GoTo Summary
End If
If (sum <> TotalCost) Then
NoMatch.Show()
GoTo GoHere
End If
Summary:
Summary.show()
When a script uses GoTo to go back to a previous question, the interviewing program does not reset any of the questions or temporary variables that exist between the GoTo and that question. This means that any question that becomes off-path during the rerun still retains its data. If there is filtering or routing based on this question later in the script, this can result in the wrong path being taken from that point onwards. To see this, let’s use the same sets of answers that were used for the save point illustration.
Parameter
|
Answer
|
TotalCost
|
100
|
Food
|
70
|
HadDrinks
|
Yes
|
Drinks
|
25
|
Service
|
10
|
After answering the questions for the first time, the respondent reaches the statement that compares the sum with the total cost. The two values do not match so the script displays an error message and skips back to the GoHere label. This does not change any of the existing answers, so as each question is reached, the respondent sees the previous answer displayed and can either click Next to accept it or type in a new answer.
If the respondent gives the same set of second answers as in the first test, they will not see the Drinks question. However, because it was not reset during the rollback, the original answer will still exist even though it no longer contributes towards the total. When the summary is displayed it will show the following values:
Parameter
|
Answer
|
TotalCost
|
80
|
Food
|
70
|
HadDrinks
|
No
|
Drinks
|
25
|
Service
|
10
|
Drinks is still 25 even though HadDrinks is now No. It is for this reason that you are advised to use roll back interviews using save points rather than GoTo.
The default procedure for dealing with off-path data is to set it to null when the interview ends, so the fact that Drinks contains data will not affect the validity of your case data. However, this would not be the case if you changed the behavior so that off-path data was kept. For more information, see
Dealing with off-path data.
See also