Guidelines to convert macro into a SVB node in a workspace
book
Article ID: KB0075422
calendar_today
Updated On:
Products
Versions
Spotfire Statistica
13.3 and later versions
Description
Recorded an SVB macro that needs to be made into a custom node. In the below context, we will only explore SVB node of the type : AnalysisNode through an example.
Issue/Introduction
Guidelines to convert macro into a SVB node in a workspace
Resolution
There is no main function in a svb nodes, so to convert a recorded macro into SVB node, we have to first understand the node context. A SVB node of type : AnalysisNode would expect 3 parameters : dataIn() of type : InputDescriptor : The array of spreadsheets coming from upstream into the node reportDocs of type: StaDocCollection : The Statistica document collection that can have any type of Statistica object (spreadsheet,graph, or report) that should be part of the reporting workbook dataOut() of type : InputDescriptor : The array of spreadsheets going downstream from the node
For the purpose of this article we will be recording a macro and tinker it to be a node.
Step 1: To record the macro
1. Click on Home >>Open >>Open Examples >>Datasets >>Characteristics.sta 2. Click on Statistics >>Basic Statistics >> Descriptive statistics. Click OK 3. Click Variables and select variables 4-8. Click Ok. 4. Click on Options in the analysis and select 'Create Macro...'
5. Click on OK to generate the macro. Keep the macro and spreadsheet open. Copy of the recorded macro is attached for reference: Recorded Macro- Chr_BAS_Stats.svb
Step 2: Let's make a custom SVB Node
1. Click on Home >>New >> Workspace and select to use a Blank template 2. In the Select Data Source dialog, choose : Characteristics.sta that is open 3. Click on the Node Browser icon to open Node browser and locate : Publish >>Create Code Node>> SVB Node
4. Refer to the recorded macro. Copy any references to any libraries in the recorded macro. Our first step is to convert ActiveInputDataset into node terms. i.e to get the spreadsheet from dataIn()
Double click on the SVB node and select code. Define a spreadsheet object : Dim sInput as Spreadsheet. Loop through the array of InputDescriptor DataIn() to get the input spreadsheet as shown below :
Click OK to save the code so far.
5. Refer back to recorded macro and copy the contents of the main function into SVB Node Code as shown below. Replace ActiveDataset with the spreadsheet variable that contains the input spreadsheet (SInput) .
Note : Also copy any references that the recorded macro may have by copying the macro into a note pad and then copying the lines that start with '#Reference to the top of the macro.
6. Scroll to the bottom of the code and add these lines to grab the output of oStaDocs into a spreadsheet with the statements : Dim sOut As Spreadsheet Set sOut = oStaDocs.Item(1)
7. To add results to the reporting documents , add the line : reportDocs.Add(sOut). To pass the spreadsheet downstream, add the lines : Dim idOut As New InputDescriptor idOut.DataSource = sOut ReDim Preserve dataOut(i) As InputDescriptor Set dataOut(i) = idOut
In other words, we are creating a new Input descriptor array, defining the size of the array and assigning its dataSource to be the output spreadsheet. We are then setting the new Input descriptor to be the output InputDescriptor object.
Step 3: Optionally add parameters to the SVB Node You may optionally choose to have input parameters for the node, instead of hard-coding certain options in the macro. If you choose to do this, identify the parameters you'd like to use in the code and its type. Let us say for this example, that we want the user to be able Select variables as a parameter for this node. 1. Open the SVB node by double clicking on it, click on Parameters and click on + to add a parameter. 2. Choose the type of Parameter (in this case Variable Selection) and select a name (that it will be referred to in the macro) and the display Name (The display that describes what the parameter is used for)
3. Click OK. Click on Code and add the below lines of code as shown below :
Dim sVar as String sVar= Dictionary("depVar")
Change the line where the variables are hard-coded to use the variable that contains the value of the parameter.
4. Click OK to save the code and run the node to ensure that it does not error out.
5. Note that instead of the above described dictionary parameter, we could also get the input from the spreadsheet by using :
Dim StrVarIndex as String strVarIndex = dataIn(i).ContinuousDependentVariablesString
Example workspace that contains examples of all 3 parameter options for variables described in this article is attached.
Step 4: Distribution of custom SVB Node
1. To distribute the custom node to other users, double click on the node and click on Export Node. 2. Name the node and choose a path to save the node. Save to a shared drive location, if necessary.
3. Click OK on the message that indicates the node has been exported.
4. Open Node Browser on the target machine and choose a folder to import the node. Click on the blue box icon and then select Import New node.
5. Select the dmi from the path it was saved to. This will add the node for the machine and the user adding the node. 6. Steps 4-5 can be repeated for every user who desires to use the custom node. Alternatively, the nodebrowser.xml can be copied from the user who imported the node : C:\Users\[username]\AppData\Roaming\StatSoft\STATISTICA\[Version] into the other user directories by an administrator.
To deploy, you may also alternatively deploy to Enterprise a template workspace and share the workspace with users who would like to use in their workspaces. The node can be copied from the template workspace into the workspace that is being developed.
Additional Information
You may refer to sdn.chm in Statistica Installation directory to become more familiar with the Statistica visual basic (SVB) object modelĀ
Attachments
Guidelines to convert macro into a SVB node in a workspace
get_app
Guidelines to convert macro into a SVB node in a workspace
get_app