STATISTICA







Using STATISTICA Development Environment from within Visual Basic

Example 1: This example, vbtest.xls, uses the STATISTICA Development Environment to open a user-specified STATISTICA data file in ms Excel. Note that the Stadev32.dll must be placed in either the Windows System or the Excel directory so that it is visible for Visual Basic run time.


Visual Basic Code

'Declare the necessary STATISTICA Development Environment functions.
Declare Function StaOpenFile Lib "stadev32.dll" (ByVal szFileName As String) As Long
Declare Function StaGetData Lib "stadev32.dll" (ByVal hSF As Long, ByVal Var As Integer, ByVal CaseNo As Long, ByRef Value As Double) As Integer
Declare Function StaGetNVars Lib "stadev32.dll" (ByVal hSF As Long) As Integer
Declare Function StaGetNCases Lib "stadev32.dll" (ByVal hSF As Long) As Long
Declare Function StaCloseFile Lib "stadev32.dll" (ByVal hSF As Long) As Integer
Declare Function StaGetVarName Lib "stadev32.dll" (ByVal hSF As Long, ByVal Var As Integer, ByRef szName As String) As Integer
Declare Function StaGetCaseName Lib "stadev32.dll" (ByVal hSF As Long, ByVal CaseNo As Long, ByVal szName As String, ByVal BL As Integer) As Integer
Dim d As Double

Sub Macro1()
    'Prompt the user for the .sta file to open.
    myfile = InputBox(Prompt:="Enter the name of the file you would like to open", Title:="Enter filename", Default:="c:\stat\examples\adstudy.sta")
    'Open the user-specified .sta file.
    mydata = StaOpenFile(myfile)
    'Determine the number of variables and cases of the user-specified data file.
    numvar = StaGetNVars(mydata)
    numcas = StaGetNCases(mydata)
    'Put the data file name in the 4th row and 1st column on Sheet1.
    Worksheets("Sheet1").Cells(4, 1) = myfile
    'Begin loop to assign individual cells.
    Cells(5, 1).Activate
    For i = 1 To numvar
      For j = 1 To numcas
        Cell = StaGetData(mydata, i, j, d)
        ActiveCell.Offset(j, i - 1).Value = d
      Next j
    Next i
    'Close the .sta file.
    StaCloseFile (mydata)
'End program.
End Sub
Back to List of Programs


[StatSoft]
2300 East 14th Street, Tulsa, OK 74104
Phone: (918) 749-1119; Fax: (918) 749-2217

[StatSoft]e-mail: info@statsoft.com

©Copyright StatSoft, Inc., 1984-2005.
StatSoft, StatSoft logo, STATISTICA, SEWSS, SEDAS, Data Miner, SEPATH and GTrees are trademarks of StatSoft, Inc.