AnsweredAssumed Answered

How add a new dataset to Processbook with vba?

Question asked by valmir paixao on Aug 24, 2015
Latest reply on Aug 25, 2015 by Kenji Hashimoto

Hi everyone.

I already have an example of how create a DataSet with VBA, but, on this example adds an new dataset on a PB trend.

What I need to do is add this new dataset on my PB display as it was an PI value.

I would like to have a clue how modify the code below and show the new dataset on PB display instead of put it on PB trend.

Many thanks. Valmir




Sub CreateAndPlotDataset()

    Dim MyDatasets As Datasets

    Dim MyDataset As PIExpressionDataset

    Dim MyTrend As Trend

    Dim MyTrendFormat As TrendFormat

    Dim MyBool As Boolean

    Dim ds_name As String



    ds_name = "teste_dois"

    Set MyDatasets = ThisDisplay.Datasets

    Set MyDataset = MyDatasets.Add(ds_name, Nothing, True, 1, True, pbDatasetPIExpression)

    Set MyDataset = MyDatasets.GetDataset(ds_name)

    MyDataset.servername = "S8DDPI01"

    MyDataset.Expression = "If TagVal('BA:Active.1','*') = ""Active"" Then 'CDT158' Else NoOutput()"

    MyDataset.RefreshInterval = 60000

    MyDataset.ColumnName = "Value"

    MyDataset.Interval = "1h"

    MyDataset.Description = "Calculated Dataset"

    MyDatasets.SetDataset MyDataset


'###Here I would like  to show this new dataset on PB display instead of put it on a trend.


    Set MyTrend = ThisDisplay.Symbols.Add(pbSymbolTrend)

    Set MyTrendFormat = MyTrend.GetFormat

    MyTrendFormat.ShowTraceMarkers = True

    MyTrend.SetFormat MyTrendFormat

    MyTrend.Top = 14900

    MyTrend.Left = -14900

    MyTrend.Height = 1000

    MyTrend.Width = 1500

    MyBool = MyTrend.SetStartAndEndTime("*-1d", "*")

    MyTrend.AddTrace "NewCalc.Value"


End Sub