In our last article we showed you the steps that you need to take to produce tables in Data Collection. Open the data , create the table structure , populate the tables and then export. In this article we will spend some time showing you how to create some of the different tables that you may need and some of the basic additions that we need to add to our script to make it run smother.
In this article we will use the file that we setup last time and continue to add to that. The first table we created was a table with the age question.
oTableDoc.Tables.AddNew("Table1", "age", "Table1")
You should have noticed that when you run your script the second time that it errors saying that you cannot run the script because the output file already exists. If this is the case then what we can do is to add some additional
to our export section so that we overwrite the file. Theis ,' Export the tables With oTableDoc.Exports["mrHtmlExport"] SetProperty(.Properties, "OverwriteOutput", True) .Export("c:tempoutput.htm") End With Sub SetProperty(Properties, Name, Value) Dim Property Set Property = Properties.FindItem(Name) If IsNullObject(Property) Then Set Property = Properties.CreateProperty() Property.Name = Name Property.Value = Value Properties.Add(Property) Else Property.Value = Value End If End SubAs you can see we have added the "SetProperty(.Properties, "OverwriteOutput", True)" line to the exports section. We have had to add the SetProperty function to limit the amount of
that we have to type. There are many different properties that we can assign to the export section , and we will have a look at these in later articles , so having a function is better coding. Another thing we should add to our script before we continue is the feature that allows us to show the filter and titles etc that we have applied to our tables. So to our TableDoc.Default section,With oTableDoc.Default .Clear() With .CellItems .AddNew(0 '! Count !') .AddNew(1 '! ColPercent !') End With End Withwe will add the following Annotations,
With oTableDoc.Default
.Clear()
With .CellItems
.AddNew(0 '! Count !')
.AddNew(1 '! ColPercent !')
End With
.Annotations[0 '! TitleHeader !'].Specification = "{ProjectDescription}"
.Annotations[1 '! LeftHeader !'].Specification = "{TableDescription n}{Filters p}"
.Annotations[3 '! RightHeader !'].Specification = "{TableNumber p n}{WeightVariable l p n}{Level l p}"
.Annotations[5 '! LeftFooter !'].Specification = "{CellContents p n}{Statistics p n}{Rules p}{CellItemSymbols p}{PopulateWarnings p}"End With
With the use of annotations we can place text around our tables in 8 different places. To find out what these locations are use the DDL and search for "Annotations" so back to our tables
As you will see from the output this puts the age question on the side of the table. If you want to put the age question on the top of the table then you need to place an * in front of it , like this.
oTableDoc.Tables.AddNew("Table2", "* age", "Table2")so from that you should be able to guess to cross a question by a question we put an astrix in-between the two questions like this.
oTableDoc.Tables.AddNew("Table3", "age * before", "Table3")You should also notice that now we have our annotations you can see the table titles, filters and cell contents as well as the table.
Next we will look at how we nest variables inside of each other as well as putting questions next to each other. To nest a variable we use the > sign.
oTableDoc.Tables.AddNew("Table4", "age * before > gender", "Table4")and to add a question to the side of another you use the + sign
oTableDoc.Tables.AddNew("Table5", "age * before + gender", "Table5")If you have not noticed already we have only be working with categorical questions. In our next article we will show you how tabulate numerical or text questions.