4 Replies Latest reply on May 26, 2009 1:02 PM by AlistairFrith

    Creating a dataset in code

    AlistairFrith

      Similar to the 'Editing a dataset in code' thread, I am writing a VB.Net Processbook addin that needs to create a dataset in code and then edit it. Here's my code:

      Dim ds As PBObjLib.Dataset
      ds = m_Application.ActiveDisplay.Datasets.Add("MyNewDS", pINewdataset)

      as instructed by the Processbook VBA language reference. However, that is talking about VBA within Processbook and this is in VB.Net so I get the error

       

      Error    7    Name 'pINewdataset' is not declared.

       

      so how do I get it to recognise pINewDataset? Or is there something else I should put as the provider?

       

      Also, are there implications for datasets when viewed in ActiveView? The .Net Addin is not used in ActiveView, it only creates the displays but the displays will contain datasets. do I need to be wary of this?

       

      Regards,

       

      --- Alistair.

        • Re: Creating a dataset in code
          AlistairFrith

          Sorry for bothering you guys, after a little more searching I think I have the answer. Seems that if it is a simple calculation dataset (which it is), then I can supply 'Nothing' as the provider:

          Dim ds As PBObjLib.Dataset
          ds = m_Application.ActiveDisplay.Datasets.Add("MyNewDS", Nothing)

          Regards

           

          --- Alistair.

          • Re: Creating a dataset in code
            dhollebeek

            Just in case people who read this thread are curious:  pINewDataset is a pointer to a IDataProvider (usually an IDataProvider3 these days).  If you're adding a *custom* dataset you can pass in a pointer to the object which implements the IDataProvider interface for the dataset and then PB will ask that object for the dataset's data (via the interface) whenever it need data from the dataset.

             

            According to the help file, what you are doing should result in an error (NULL interface pointer for type pbcDatasetAddIn), but don't worry, we don't close these types of loop-holes in PB because people might be using them (intentionally or not).

              • Re: Creating a dataset in code

                To add to David's note on the incorrect use of DataSets.Add, I was curious to see the rest of your code and how you make use of the "ds" variable). Essentially, you are creating an "Add-In data set" (pbDatasetAddIn - not pbcDatasetAddIn, David ), but according to your 2nd post you are trying to create a "PI Expression data set" (pbDatasetPIExpression).

                 

                I would suggest you do the following instead:

                Dim ds As PBObjLib.PIExpressionDataset
                ds = m_Application.ActiveDisplay.Datasets.Add("MyNewDS", Nothing, , , , pbDatasetType.pbDatasetPIExpression)
                ds.Expression = "expression"
                ds.Interval = "interval"
                ds. ...

                Note that in this code, an implicit conversion is being done at Datasets.Add (from PBObjLib.Dataset to PBObjLib.PIExpressionDataset). In C# you would need to to an explicit conversion (cast) and it's also a good practice in VB.NET:

                ds = DirectCast(m_Application.ActiveDisplay.Datasets.Add("MyNewDS", Nothing, , , , pbDatasetType.pbDatasetPIExpression), PBObjLib.PIExpressionDataset)

                Hope this helps!