Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Ending, suspending, and rolling back interviews > Save points, rollbacks and replays > Comparison of rollbacks to save points and rollbacks using GoTo

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
Total cost {#TotalCost}
Food cost {#Food}
Drinks cost {#Drinks}
Service cost {#Service}<br/>
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
sum = Food
sum = sum + Drinks
End If
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
TotalCost
100
Food
70
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 have no value. When the value of an off-path question is checked in script, its value is empty. However, as each question is asked again, the previous answer, or off-path response, is displayed. If the off-path response also needs to be cleared, you can use the ClearOffPathResponse method: see Dealing with off-path data.
Using GoTo
Here is the same routing section written using GoTo:
Dim sum
GoHere:
sum = Food
sum = sum + Drinks
End If
sum = sum + Service
' This stops the script getting into an infinite loop
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
TotalCost
100
Food
70
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 do not see the Drinks question. However, because it was not reset during the rollback, the original answer still exists, even though it no longer contributes towards the total. When the summary is displayed, it shows the following values:
Parameter
TotalCost
80
Food
70