Statistical Analysis

Other topics about Sample Programs

Overview

This sample program demonstrates how to perform statistical analysis. It performs statistical analysis on the specified measurement items and then retrieves and displays the results of the analysis.

See these topics for this programming:

Statistical Analysis of Measurement Results

Performing Statistical Analysis

Sample Program in Excel VBA Using VISA-COM

Sub StatisticalAnalysis()

'Performs statistical analysis on the specified measurement items and

'then retrieves and displays the results of the analysis.

    Dim Title(7) As String

    Dim Para As String

    Dim Point As Double

    Dim Number As Integer

    Dim dispStat As Integer

    Dim Item As Integer

    Dim i As Integer

    Dim examOpt As String

    Dim ioMgr As VisaComLib.ResourceManager

    Dim age4982x As VisaComLib.FormattedIO488

    'Sets the GPIB address

    Set ioMgr = New VisaComLib.ResourceManager

    Set age4982x = New VisaComLib.FormattedIO488

    Set age4982x.IO = ioMgr.Open("GPIB0::17::INSTR")

    age4982x.IO.Timeout = 30000

    'Checks the number of measurement data segments for statistical

    'analysis stored in the volatile memory. If no such data exists, the

    'program displays a message and terminates

    age4982x.WriteString ":CALC:EXAM:POIN?"

    Point = age4982x.ReadNumber

    

    If Point < 1 Then

        MsgBox "No data!!"

        GoTo Prog_end

    End If

    

    'Checks whether each measurement item is currently shown or hidden

    'and stores the names of the currently shown items into the Title()

    'array and the number of the shown items into the Number variable.

    'The measurement items include measurement parameters 1 through 4,

    'the monitored values of the test signal current and voltage levels,

    'and the result of Rdc measurement

    Number = 1

    For i = 1 To 4

        age4982x.WriteString ":DISP:TEXT1:CALC" & i & "?"

        dispStat = age4982x.ReadNumber

        If dispStat = 1 Then

            age4982x.WriteString ":CALC:PAR" & i & ":FORM?"

            Para = age4982x.ReadString

            Title(Number) = "Parameter " & i & " -" & Para

            Number = Number + 1

        End If

    Next i

    

    age4982x.WriteString ":DISP:TEXT1:CALC11?"

    dispStat = age4982x.ReadNumber

    If dispStat = 1 Then

        Title(Number) = "I Level Monitor"

        Number = Number + 1

    End If

    

    age4982x.WriteString ":DISP:TEXT1:CALC12?"

    dispStat = age4982x.ReadNumber

    If dispStat = 1 Then

        Title(Number) = "V Level Monitor"

        Number = Number + 1

    End If

    

    'age4982x.WriteString ":SOUR:LIST:RDC ON"

    age4982x.WriteString ":SOUR:LIST:RDC?"

    dispStat = age4982x.ReadNumber

    If dispStat = 1 Then

        Title(Number) = "Rdc Measurement"

        Number = Number + 1

    End If

    

    Number = Number - 1

    

    'If Number is 0, the program displays a message and terminates

    If Number = 0 Then

        MsgBox "No Analysis Item!!", vbOKOnly

        GoTo Prog_end

    End If

    

    On Error GoTo Item_select

    

Item_select:

    'Display the list of items that can be statistically analysed and prompts

    'the user to choose one of the items by typing in the appropriate number

    examOpt = ""

    For i = 1 To Number

        examOpt = examOpt + "  " & i & " : " & Title(i) & vbCr

    Next i

        

    Item = Val(InputBox("[Statistical Analysis]" & vbCr & "Select Analysis Item" & vbCr _

            & examOpt & vbCr & "Input 1 to " & Number))

    If Item < 1 Or Item > Number Then

        GoTo Item_select

    End If

           

    'Display the names of the measurement items selected for statistical analysis

    'and then passes control to a subprogram names Stat_ana to perform statistical

    'analysis and display the results

    MsgBox "Analysis Item: " & Title(Item)

    Call Stat_ana(age4982x, Item)

Err.Clear

    

Prog_end:     End

    'Allow the user to return to the entry start line and re-enter the data if

    'an error (such as an invalid entry) occurs while selecting the number

    'identifying the measurement items on which to perform statistical analysis

End Sub

    

    '========================================================

    ' Statistical Analysis Function

    '========================================================

Public Sub Stat_ana(LCRMeter As VisaComLib.FormattedIO488, Item As Integer)

    Dim Res(32, 10) As Double

    Dim listStat As Integer

    Dim Nop As Integer

    Dim i As Integer

    Dim J As Integer

    Dim FirstRow As Integer

    Dim strResult() As Double

    Dim measPoint As Double

    'Retrieve the list(1)/single-point(0) measurement setting and stores the setting

    'into the listStat variable

    'LCRMeter.WriteString ":SOUR:LIST:STAT 1"

    LCRMeter.WriteString ":SOUR:LIST:STAT?"

    listStat = LCRMeter.ReadNumber

    If listStat = 1 Then

        'If list measurement is specified (listStat = 1), the program retrieves the

        'number of measurement points and stores the data into the Nop variable

        LCRMeter.WriteString ":SOUR:LIST:SIZE?"

        Nop = LCRMeter.ReadNumber

    Else

        'If single-point measurement is specified (listStat 1 variable not equal to 1),

        'the program stores 1 into the Nop variable

        Nop = 1

    End If

    

    'Performs the measurement items identified by the Item variable and then retrieves

    'the results and stores them into the Res() array. The subprogram repeats these

    'steps for all the measurement points

    For i = 1 To Nop

        LCRMeter.WriteString ":CALC:EXAM:GET? " & Item & ", " & i

        strResult() = LCRMeter.ReadList(ASCIIType_R8, ",")

        

    Next i

    

    'Displays the results of the statistical analysis

    FirstRow = 15

    Cells(FirstRow, 1) = "Point)"

    Cells(FirstRow, 2) = "Mean"

    Cells(FirstRow, 3) = "Sigma"

    Cells(FirstRow, 4) = "3*Sigma/Mean"

    Cells(FirstRow, 5) = "Min"

    Cells(FirstRow, 6) = "Max"

    Cells(FirstRow, 7) = "Total"

    Cells(FirstRow, 8) = "Rdc Fail"

    Cells(FirstRow, 9) = "Overload"

    Cells(FirstRow, 10) = "Abnormal"

    Cells(FirstRow, 11) = "All"

    For i = 1 To Nop

        For J = 0 To 10

            If J = 0 Then

                Cells(i + FirstRow, J + 1) = i

            Else

                Cells(i + FirstRow, J + 1) = strResult(J - 1)

            End If

        Next J

    Next i

End Sub