8 Replies Latest reply on Jul 19, 2016 7:54 PM by PeterTang

    PI ProcessBook Data Set Change Server from VBA

    PeterTang

      Hi Everyone,

       

      Is there a way to change the server referred to in a data set from VBA in PI ProcessBook?

       

      Thanks.

        • Re: PI ProcessBook Data Set Change Server from VBA
          hwustrack

          Hi Peter,

           

          John Messinger's response in this previous PI Square post may prove helpful here:
          Problem creating a PIExpression dataset in Processbook 2015 Version 3.5.0.284.

          Set myDataSets = ThisDisplay.Datasets  
          Set myDS = myDataSets.Add("Test", Nothing, True, 1, True, pbDatasetPIExpression)  
          Set myDS = myDataSets.GetDataset("Test")  
          With myDS  
              .ServerName = "SOCC"  
              .Expression = myExp  
          '    .Expression = "'sinusoid'*3"  
              .Description = "Edit at " & Now()  
              .ColumnName = "Value"  
              .RefreshInterval = 3600  
              .Interval = "10M"  
          End With  
          myDataSets.SetDataset myDS  
          
          1 of 1 people found this helpful
            • Re: PI ProcessBook Data Set Change Server from VBA
              PeterTang

              Hi Hans,

               

              I'm getting "Object doesn't support this property or method" errors when trying to use the "myDataSets.SetDataset". This is when attempting to edit it at the ProcessBook level. Are there certain conditions that need to be met?

               

              Thanks.

                • Re: PI ProcessBook Data Set Change Server from VBA
                  hwustrack

                  Hi Peter,

                   

                  Are you using GetDataset to get an editable copy of that data set as below?

                   

                  Dim MyEditDataset as Dataset
                  
                  ‘ Use the Datasets.GetDataset to obtain an editable copy of the desired
                  ‘ dataset
                  Set MyEditDataset = ThisDisplay.Datasets.GetDataset("NewOne")
                  MyEditDataset.Visible = True
                  MyEditDataset.Description = "Modified Dataset"
                  MyEditDataset.Stepped = True
                  
                  ‘ The changes are not made permanent until the Datasets.SetDataset is
                  ‘ called
                  ThisDisplay.Datasets.SetDataset MyEditDataset
                  

                   

                  Also, what type of data set are using in this case? This page in our documentation goes over the differences:

                  PI ProcessBook

                    • Re: PI ProcessBook Data Set Change Server from VBA
                      PeterTang

                      Hi Hans,

                       

                      Yes, I'm using GetDataset to get an editable copy. All the data are PI calculations.

                       

                      A snippet of the code:

                          Dim dss As Datasets

                          Dim ds As Dataset

                         Dim i, nds As Integer

                         Dim ToReplaceServerM As String

                         Dim oBook As ProcBook

                       

                      <other stuff>...

                       

                          Set dss = oBook.Datasets 'get all data sets

                          nds = dss.Count 'number of data sets

                          For i = 1 To nds

                              Set ds = dss.GetDataset(i)

                              If ds.Type <> 3 Then '3 doesn't have a server name

                                  If LCase(ds.ServerName) = ToReplaceServerM Then 'check if it's the server to replace and replace it

                                      ds.ServerName = ReplacementServerRaw

                                      dss.SetDataset (ds) 'Errors out here

                                  End If

                              End If

                          Next i

                       

                      Thanks