Objects
Objects are the components of a script. They include questions, categories, labels, and styles; in fact, everything you can find in the Interview Object Model diagram. You can add objects into an interview so that you can use them during the interview in the same way that you use the standard objects. A typical example is where you want to use a set of records in an SQL database as the response list to a question. The records still exist only in the SQL database, but by creating an object that links to them, you are able to use them as if they were defined in the script. Other examples of objects you might use are File System Objects or XML DOM objects.
Before you can use objects you must create and initialize them. You do this in the OnInterviewStart event.
1 Create the object by typing:
Dim <variable>
Set <variable> = CreateObject("<name>")
where:
<variable> is a variable name that can be used to represent the object.
<name> is the name of the object you want to create.
2 Initialize the object. How you do this depends on what the object is for, but, for an ADO recordset, for example, you would load records into the object.
3 Add the record to the interview objects collection:
IOM.Objects.AddNew("<name>", <variable>)
where:
<name> is the name of the object.
<variable> is the name of the variable that represents the object (the one that you defined with Dim).
For example:
Sub OnInterviewStart(IOM)
Dim rsLongBrandList
Set rsLongBrandList = CreateObject("ADODB.RecordSet")
rsLongBrandList.Open("SELECT Brand FROM Brands",_
"Provider=MSOLEDBSQL.1;Data Source=SVR1")
IOM.Objects.AddNew("rsBrandList", rsLongBrandList)
End Sub
This example creates an ADO recordset for use later in the interview.
To use an object during the interview, refer to it as:
IOM.Objects.ObjectName
Objects exist only for the life of the interview. If the interview times out or is stopped, the objects “disappear” and must be recreated if the interview is started.
If your object has child objects, you can assign the child objects to variables in a similar way to the way you assign objects to variables. For example:
Set MyFields = MyObject.Fields
The variables to which the child objects are assigned will not be available after a restart unless they appear between two .Ask statements.
Temporary variables (that is, those that you define in the routing section using Dim) are not objects, and cannot be added to the Objects collection. If you want to save or write out the values of temporary variables, put them in project or interview properties as illustrated in the EnglishMuseum_WithParadata.mdd example script discussed in Paradata Example Script.
See also