Learn Tables : One Table

In the past we have done lots of articles about creating surveys and all the things that you might want to do with them , so now we thought it was time to run some articles on tabulation. As you know , we have four products that you can use to create tables in Data Collection and in these articles we are only going to use Professional and scripts. So in this first article we will look at how we load up a datafile create one table and export it to HTML.

So first off we need to get some data to use. In our examples we will use data from the DDL and in this case we will use the museum.ddf file. So what do we do , well the first thing we need to do is to create an MRS file in professional and create some variables.

Dim oTableDoc
Dim sPath

sPath = "C:\Program Files\IBM\SPSS\DataCollection\6\DDL\Data\Data Collection File"

' Create a new Document object
Set oTableDoc = CreateObject("TOM.Document")

So first off we have created a variable that we will use as our tables document. The tables document is the object that we add the tables to so this is why we have called it the “oTableDoc”. Next we have a string variable that we use to hold the location of the data file and then we use the CreateObject command to connect to the”TOM.Document” , TOM stands for Tables Object Model, and turn the oTableDoc variable into an object that has all the features that we need to create some tables.

Now that we have our files setup we need to load the data. As mentioned before in this example we are going to use the museum.ddf

' Load the dataset
With oTableDoc.DataSet
    .Load(sPath + "Museum.mdd" , , sPath + "Museum.ddf", "MrDataFileDsc")
    .View = 1 ' HDATA
End With

The first thing we have done is to use a with statement on the “TableDoc.DataSet” to load the data and set the View to use as the HDATA or Hierarchical Data view. As you can see the .Load function has 4 parameters. The first two specify the metadata to use , the first is the file itself and the second is the DSC to use to read the file , you will notice that in our example the second option is blank , this is because we are using an MDD file. If our metadata was a SAV file then we would have the name of the sav dsc there. The next two parameters specify the data file and the dsc to use to read it.

Now that we have our data loaded next we need to setup some defaults. In our case we will just say that each table will have a count and a col percent.

With oTableDoc.Default
    .Clear()
    With .CellItems
        .AddNew(0 '! Count !')
        .AddNew(1 '! ColPercent !')
    End With
End With

Again we have used the with statement to connect to the .Default settings of our object. The first thing we do is to clear any defaults that may be setup and then add the two new items , a count and a Col Percent. You will notice that the count has a value of 0 and the column percent is 1. There are lots of different things that you can add into the cells of your tables and to find out all the numbers to use look in the DDL for “Available Cell Contents”.

The next thing that we need to do is to setup the filter for the data that we are going to use,

oTableDoc.Global.Filters.AddNew("InterviewFilter", "(NOT (DataCollection.Status >= {Test})) AND (DataCollection.Status.ContainsAny({Completed}))", "Real data, completed")

as we can see we add the filter to the table document at the global level , we give our filter a name “InterviewFilter” and then we put in the

 to create the filter and in our case we say not any test data and only records that have been marked up as Completed. After the 
 for the filter we have a title for our filter "Real data, completed" that we will see in the tables.

Now that we have setup the environment for our tables we can start to create the tables themselves. In this example we are going to create a very simple table with just one question in it.
oTableDoc.Tables.AddNew("Table1", "age", "Table1")

so what we have done is to take our table document and to the tables collection add a new table. The name of our table is "Table1". Next we have the questions used in the table "age" followed by the title of the table. Now that we have our table we need to populate and export it.

oTableDoc.Populate()

With oTableDoc.Exports["mrHtmlExport"]
    .Export("c:\temp\output.htm")
End With

In our example we have produced an html output but as we will see in future articles you can go to Word, PowerPoint , Excel and text. So there you have it a very simple script that will produce one table and chart of the selected question.

Age Question

1 thought on “Learn Tables : One Table”

Leave a Comment