theThought's thoughts

Kevin A Gray - Creative Strategy Guy

IBM SPSS Data Collection Consumes DLL to push data into OpenXML

 

So the class required to push data into an OpenXML Word document has now been created (the class), there are just three steps left:

·         Create the DLL wrapper and publish

·         Create a test Chassis to ensure that the DLL works and resolve issues

·         Integrate the DLL into the Data Collection routing and test the final integration

Details of each of these steps is below:

Create the DLL wrapper and publish

Data Collection is able to integrate with processes that are exposed as COM components.  At present the DLL that has been created is not exposed in this way consequently some changes have to be made. This is done by changing the definition of the class and is described by the following article (com objects in vb.net).  Many of these steps have already taken place.  As this particular class does not use or consume events I did not create an Events Id.  Also I used Visual Basic Express 2008 to create my DLL and this does not have the GUID creating tool referenced in the document.  Consequently I used a website to do this (oh the beauty of the internet),  this site is fantastic in its simplicity (create a GUID).

Effectively I did two things:

I replaced the Class definition

Public Class Complaint

with

<System.Runtime.InteropServices.ProgId("cao2.Complaint"), ComClass(Complaint.ClassId, Complaint.InterfaceId)> Public Class Complaint

   Public Const ClassId As String = "CB3F9E3E-D1EB-4852-9C34-7C0A6DC4F7F8"
   Public Const InterfaceId As String = "9C10A919-8E4B-419E-9AAE-3868A1466EC4"

Following this two Constants are generated for the ClassID and InterfaceID GUIDs.  They are kept as constants to make sure that they are the same between compilations of the DLL

Lastly the Properties of the Project are changed so that the Assembly knows it needs to make the assemblies COM visible.  This setting is shown in the following diagram:

Image001

Create a test Chassis to ensure that the DLL works and resolve issues

Once the DLL has been constructed it needs to be tested.  A test chassis is needed to be able to define the DLL and pass the UpdateCustomPart method with the necessary details.  I used a project I had created earlier (first project) that I built as a chassis as it has a form interface and already has the right references. I added a RichTextBox so that the output from the survey (survey output) could be copied into the Chassis and passed to the DLL.  The form now like the one shown below:

Image002

Once the form was finished the references within the project were changed so that the chassis is aware of the newly created DLL.  The reference can be seen on the second line of the following diagram.  It was created by adding a reference and pointing to the DLL that was created when the DLL was compiled.

Image003

Next the start button was re-coded so that it creates a new instance of the RailComplaint class and then calls the UpdateCustomPart passing the relevant information into the method.  The information it passes is the name and location of the Word Document (hard coded for this test), the name of the CustomPart (again hard coded), and the content of the rich text box that should contain the XML string from the survey.

Private Sub pbnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbnStart.Click

‘Update Custom Part Test

Dim RailComplaint As New RailComplaint.Complaint
Dim Result As Boolean

Result = RailComplaint.UpdateCustomPart("C:\projects\OpenXML\Samples\RailComplaint\Customer Complaint Test.docx", "item1", rtbXML.Text)

End Sub

Once this is complete IBM SPSS Data Collection – Author Professional is run  and the survey is loaded.  Auto-Answer is used to populate the responses and generate the XML.  The last line of code sends the XML to the output window: Debug.log(xmlPart.xml).  Once the survey is complete the contents of the output window can be copied into the RichTextbox in the test Chassis.  Finally, the start button can be pressed and the code executed.  The script provided in this and other posts has already gone through this process so should work without issue.

Integrate the DLL into the Data Collection routing and test the final integration

The final stage of the process is to call the DLL from the survey.  The code used to do this is very similar to that used in the test harness.  DCScript variables are not typed so the declarations are simpler.  The last line just makes sure that the RailComplaint object is completely removed from memory.

Dim Result
Dim RailComplaint          

                set RailComplaint = CreateObject("cao2.Complaint")
                Result = RailComplaint.UpdateCustomPart("C:\projects\OpenXML\Samples\RailComplaint\Customer Complaint Test.docx", "item1", xmlPart.xml)
                set RailComplaint = null

Once this has been done it is possible to run the survey, complete the two pages of questions and then Open the Customer Complaint Text.docx file to see the result.

Filed under  //   CreateObject   DCScript   DLL   IBM   OpenXML   PASW DATA Collection   SPSS   WordML