Loop with variable columns - Statistica Visual Basic - Statistica - Dell Community

Loop with variable columns

Loop with variable columns

This question is not answered

Here is a part of the code I am unable to build:

Dim oAD2 As STANonlinear.NlnLSUserDefined
Set oAD2 = newanalysis2.Dialog oAD2.UserFunction = "v3=v2/(const1+v2)"
oAD2.CasewiseDeletionOfMD = True

How can I make a loop where the variable v3 changes to v4 and executes the statements... After completing the variable changes to v5
eg. After completing "v3=v2/(const1+v2)" and statements
it does "v4=v2/(const1+v2)" and statements
then it does "v5=v2/(const1+v2)"
and so on..

All Replies
  • If you search help for "For i=1", you can find some examples that loop through variables and cases. Here is some code to get you started.


    Sub Main

    Dim S1 As Spreadsheet
    Dim i As Integer

    Set S1 = ActiveDataSet

    For i=1 To S1.NumberOfVariables

    'prevent division by zero
    If (GetValidObs(S1, i)) Then

    MsgBox("V" + Str(i+1) + "=V" + Str(i) + "/(42+V" +Str(i) + ")")

    Else 'zero number of observations for the variable

    End If

    Next i

    End Sub

    Function GetValidObs(ActiveSpreadsheet, VariableNum) As Double

    Dim TotalValid As Long
    Dim i As Integer

    TotalValid = 0

    For i = 1 To ActiveSpreadsheet.NumberOfCases

    'ignore missing data and make sure case selections
    'allow its inclusion
    If Not(ActiveSpreadsheet.MissingData(i, VariableNum)) And _
    ActiveSpreadsheet.SelectionCondition.Evaluate(i) Then

    TotalValid = TotalValid + 1

    End If

    Next i

    GetValidObs = TotalValid

    End Function