Events and the interview lifecycle
The following diagram illustrates the life‑cycle of a simple interview and shows how the various events fit into it.
Interview lifecycle with events
If the respondent clicks Stop at point 1, or the script executes a Terminate() statement at point 2, the interview ends immediately and OnInterviewEnd() runs. If the interview is restarted via sample management, OnInterviewStart() runs and the interview is silently replayed, but without the events being run between questions.
If the respondent is idle for a long time at point 1, the interview times out and OnInterviewEnd() runs. If the respondent leaves their browser open and later clicks Next, OnInterviewStart() runs and the interview continues from the current point.
In both restarts there is quite a bit going on in the background that you, as a scriptwriter, need to be aware of.
▪When OnInterviewEnd() runs, it saves the current state of the interview.
▪When the interview restarts, OnInterviewStart() reloads the saved interview state.
▪Any variables that are set to an external object, such as a database connection, cannot be reconnected automatically. This must be done manually in OnInterviewStart().
▪Any scripting that appears before the first .Ask() statement is not rerun. For example, the following will not work after a restart:
Dim AdoConn
Set AdoConn = CreateObject("...")
AdoConn.Connect("...")
Age.Ask()rs = AdoConn.Execute(...)
' Do something with rs here ...
Gender.Ask()
If the interview times out on Gender, the lines shown in italics will be re-executed when the interview restarts but AdoConn will be Null (or some undefined value). By placing the statements that make the connection in OnInterviewStart() you ensure that they will be run when a new interview starts and whenever an existing interview is restarted.
See also