Accueil > Community > Automation and VBA > Apply function to a data folder > Reply To: Apply function to a data folder

#9389
Bernhard KantzBernhard Kantz
Participant

There is a manual way to achieve this. Place your function formula (starting with Arguments … and named e.g. _RMS) in the folder and drag the signals onto that formula. This creates for each signal a new formula containing the application of the function on the signal.

Using Automation this small code sample performs the same task:


Option Explicit

Const FunctionPath As String = "\RMS_func"
Const FunctionPrefix As String = "_RMS"

Public Sub ApplyFunction()
    
    Dim fldSignals As Folder
    Set fldSignals = ActiveDatabase.ActiveFolder
    
    Dim cllSignals As FpObjects
    Set cllSignals = fldSignals.Objects(fpObjectTypeDataSet)
    
    Dim dsSignal As DataSet
    Dim fmlApplSignal As Formula
    For Each dsSignal In cllSignals
        Set fmlApplSignal = fldSignals.Add(dsSignal.Name & FunctionPrefix, fpObjectTypeFormula)
        With fmlApplSignal
            .Author = "Macro ApplyFunction()"
            .Formula = FunctionPath & "(" & dsSignal.Name & ")" & vbCrLf
            .ReadOnly = True
        End With
    Next

End Sub