STATISTICA







Using STADEV with Visual Basic (32 Bit)
Reading of data

This example dumps to a debug window all information about the STATISTICA data file, including variable specifications and data values with labels.

Note that to use STADEV from 32 bit Visual Basic, you must create a module containing STATISTICA Development Environment VB header file (sd_vb32.inc); call the desired functions, and put stadev32.dll on the path or in VB directory (so it is visible for VB run time).


Private Sub example1(fname$)

Debug.Print ("STATISTICA file information")

h = StaOpenFile(fname$)
If h = 0 Then Exit Sub
Debug.Print "File name:", fname$

nv = StaGetNVars(h)
Debug.Print "Number of variables:", nv

nc = StaGetNCases(h)
Debug.Print "Number of cases:", nc

Dim fh(STAMAX_HEADERLEN + 1) As Byte
res = StaGetFileHeader(h, fh(0), STAMAX_HEADERLEN + 1)
Debug.Print "File header:", BytesToString(fh)

Dim vn(STAMAX_VARNAMELEN + 1) As Byte
Dim lvn(STAMAX_LONGVARNAMELEN + 1) As Byte
Dim wid As Integer
Dim dec As Integer
Dim typ As Integer
Dim subt As Integer
Dim md As Double
Debug.Print "Variable specs:"
For i = 1 To nv
    res = StaGetVarName(h, i, vn(0))
    res = StaGetVarLongName(h, i, lvn(0), STAMAX_LONGVARNAMELEN + 1)
    Debug.Print "Variable ", i, ": ", BytesToString(vn), "     ", BytesToString(lvn)
    res = StaGetVarFormat(h, i, wid, dec, typ, subt)
    Debug.Print "Format: ", wid, ".", dec
    res = StaGetVarMD(h, i, md)
    Debug.Print "Missing Data: ", md
Next i

Dim cn(STAMAX_CASENAMELEN + 1) As Byte
Debug.Print "Case names:"
cnl = StaGetCaseNameLength(h)
If cnl = 0 Then
    Debug.Print "No case names in this file"
Else
    Debug.Print "CN Length: ", cnl
    For i = 1 To nc
        res = StaGetCaseName(h, i, cn(0), 20)
        Debug.Print "Case # ", i, ": ", BytesToString(cn)
    Next i
End If

Dim d As Double
Dim lab(STAMAX_SLABELLEN + 1) As Byte
Dim llab(STAMAX_LLABELLEN + 1) As Byte
For i = 1 To nc
    Debug.Print "Case # ", i, ":"
    For j = 1 To nv
        res = StaGetData(h, j, i, d)
        Debug.Print d
        If 0 <> StaGetLabelForValue(h, j, d, lab(0)) Then
            Debug.Print BytesToString(lab)
            If 0 <> StaGetLongLabelForValue(h, j, d, llab(0), STAMAX_LLABELLEN + 1) Then
                Debug.Print BytesToString(llab)
            End If
        End If
    Next j
Next i
StaCloseFile (h)
End Sub
For this example you also need the following utility function in order to be able to pass string arguments by reference (they are actually passed as byte arrays and then converted to string).
Private Function BytesToString(byte_array() As Byte) As String
' convert byte array to string.
Dim Data As String, StrLen As String
Data = StrConv(byte_array(), vbUnicode)
StrLen = InStr(Data, Chr(0)) - 1
BytesToString = Left(Data, StrLen)
End Function
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-2004.
StatSoft, StatSoft logo, STATISTICA, SEWSS, SEDAS, Data Miner, SEPATH and GTrees are trademarks of StatSoft, Inc.