3 Replies Latest reply on Aug 25, 2015 1:29 PM by Kenji Hashimoto

    How add a new dataset to Processbook with vba?

    valmir paixao

      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

        • Re: How add a new dataset to Processbook with vba?
          Kenji Hashimoto

          Hi valmir,

          In my environment, following code can create PIvalue object.

          Does it work?

          Dim Newobj As Object
          Set Newobj = ThisDisplay.Symbols.Add(pbSymbolValue)
          With Newobj
          .SetTagName ("teste_dois.value")
          .DisplayPointName = 1
          .DisplayTimeStamp = 7
          .Left = -14500
          .Top = 14600
          End With
          
            • Re: How add a new dataset to Processbook with vba?
              valmir paixao

              Hi Kenji, how are you?

              Could not be better than that. Worked like a charm . You saved my day!

              Many thanks. Valmir

              Below I would like to share my final code with everyone.

               

              -----------------------------------------------------------------------------------

              Sub AdicionaDataSet(tagName As String)
                  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

                  Dim DatasetTest As Object

                  Dim tagNameText As Text

                
                  ds_name = tagName & "_average"
                  'RemoveSymbolsAndDataSet (ds_name)
                  Set MyDatasets = ThisDisplay.Datasets
                  Set MyDataset = MyDatasets.Add(ds_name, Nothing, True, 1, True, pbDatasetPIExpression)
                  Set MyDataset = MyDatasets.GetDataset(ds_name)
                  MyDataset.servername = "ServerName"
                  MyDataset.Expression = "'" & tagName & "'"
                  MyDataset.RefreshInterval = 60000
                  MyDataset.ColumnName = "Average"
                  MyDataset.Interval = "1h"
                  MyDataset.Description = "Calculated Dataset"
                  MyDatasets.SetDataset MyDataset
                 
               
                  Set tagNameText = ThisDisplay.Symbols.Add(pbSymbolText)
                  With tagNameText
                      .Contents = ds_name
                      .Top = 14950
                      .Left = -14600
                      .Visible = True
                  End With

                 
                  Set DatasetTest = ThisDisplay.Symbols.Add(pbSymbolValue)
                  With DatasetTest
                      .Top = 14950
                      .Left = -14700
                      .Visible = True
                      .SetTagName (ds_name & ".average")
                  End With

               

                 
              End Sub