macro code from StatSoft example appears to give an error - Statistica Visual Basic - Statistica - Dell Community

macro code from StatSoft example appears to give an error

macro code from StatSoft example appears to give an error

This question is not answered

Hi Forum,

I was attempting to run a macro code example given on the StatSoft developer's network.  Here is the URL:

http://sdn.statsoft.com/STATISTICAVisualBasic.aspx?page=method&class=Spreadsheet&item=VariableTextLabels&kind=sub

 

I loaded the recommended data set (Heart.sta) into a workbook along with the macro.  When I run the macro, I get this message below.  (the double quotes around the macro name are my own)

VBA Error in macro "Macro read variable text info" at line: 15

(10094) ActiveX Automation: Object var is 'Nothing'.

 

The line of code that appears to be in question is:

    spr.VariableTextLabels(1,values(),labels(),descriptions())

 

I am supposing that the code is somehow not understanding which variable to use??

The data set was set as the Active Input prior to my running the macro code.

I copied this code verbatim from the example at the URL (at least I thought I did) and ran it with the data set recommended in the example at the URL.  What have I done wrong?

I am using Statistica 64  11

AGA206F367304A11-V

 

Thanks to anyone who can set me straight on this.

 

Cliff

 

 

Here is the entirety of the code (copied from the URL above).

 

Option Base 1
Option Explicit
 
Sub Main()
'this example was written using the example data file heart.sta
    Dim spr As Spreadsheet
    'assigns the active spreadsheet to the object spr
    Set spr = ActiveSpreadsheet
    Dim values() As Double
    Dim labels() As String
    Dim descriptions() As String
    'place the text label values, labels, and descriptions into their
    'respective arrays.
    spr.VariableTextLabels(1,values(),labels(),descriptions())
    'display the first text label parameters as returned above.
    MsgBox "Value = " + Str(values(1)) + vbCrLf + "Label = " + labels(1) + vbCrLf _
           + "Description = " + descriptions(1), vbOkOnly, "Variable Text Label"
End Sub

 

All Replies
  • Hi, Cliff,

    Your error lies in placing the spreadsheet and the macro as written into a workbook. Once you've done that, the dataset is no longer a stand-alone spreadsheet but is instead a workbook item. If you try leaving the dataset and the macro as stand-alone items, the macro should run (It does for me). Otherwise, you can change the statement Set spr = ActiveSpreadsheet to Set spr = ActiveDataset. This will allow you to run the macro from a workbook with a dataset also within the workbook. By making this change, I was able to run the macro with the dataset and macro in a workbook. I do hope that you find this information helpful.  -Neptune

  • Hi Neptune,

    That's sort of what I suspected.  Essentially 'pilot error' on my part due to being new to Visual Basic.  

    I really appreciate the help, and your patience with my learning curve.  And also thanks for offering a really helpful knowledge base and forum.

    Cliff