6 Replies Latest reply on Aug 23, 2011 12:00 AM by DavidMFairchild

    Using IPIData2 interface with late binding

    DavidMFairchild
      I have an Excel VBA project that keeps dropping the references to the PISDK causing compile errors when the application opens.  To resolve this I am implementing late binding which shouldn't require the reference.  However I have a few functions that use the advanced IPI2 interface.  Typically I would implement this as ...
      ...
      dim pipt as PIPoint
      dim piDat as IPIData2
      ...
      set piDat = pipt.Data
      ...
      set nvVals = piDat.Summaries2(StartDate, EndDate, sInterval, asAverage, cbTimeWeighted)
      ...
      
      Using this the PIPoint.Data object is automatically cast into an IPIData2 interface.  But I don't know how to cast it using VBA and late binding.  As in ...
      ...
      dim pisdk as Object
      dim srv as Object
      dim pipt as Object
      dim piDat as Object 'needs to be an IPIData2 interface object
      ...
      set pisdk = CreateObject("PISDK.PISDK")
      set srv = pisdk.Servers.DefaultServer
      set pipt = srv.PIPoints("MyPoint")
      set piDat = ????
      ...
      
      Can anyone tell me how to do this? Thanks
        • Re: Using IPIData2 interface with late binding
          DavidMFairchild

          In reading a little further I see that VBA does not have the ability to type case.  This is probably because VBA is not object oriented (neither is VB6).

           

          This makes me wonder what is happening when you set an IPIData2 interface to a PIData object as in:

           

          dim ipiDat as IPIData2

           

          set ipiDat = pipt.Data

           

          Is PIData able to recognize the type it is being assigned to and convert itself to that type?  Is there some sort of overloading of the "set" expression in VBA?  How does it do this?  And how can I do it using late binding?

            • Re: Using IPIData2 interface with late binding
              ken

              David,

               

              My understanding is that you can't access secondary interfaces from VBA. So as far as I know, you are out of luck with IPIData2.

               

              But this discussion about PI-SDK programming with VBA implies otherwise:

               

              www.rjksolutionsltd.co.uk/.../yaf_postst201_Sampled-Data.aspx

                • Re: Using IPIData2 interface with late binding

                  I think the issue here is not the use of secondary interfaces when using early binding in VBA but the fact that with late binding you can only access the default interface.  There is no cast/conversion within VBA that can help with late binding for this scenario (that I am aware of).

                   

                  When you say you experience dropping of PI SDK references, have you tried using VBE (Visual Basic Extensibility) to manipulate references and ensure you have the correct ones loaded?

                    • Re: Using IPIData2 interface with late binding
                      DavidMFairchild

                      If I'm not mistaken, VBE requires that you enable VBA to access the Visual Basic Project.  This can be set under Tools | Options on the Security tab using the "Macro Security" button and the "Trusted Publishers" tab.  The company I am supporting will disable this using McAffee Anti-Virus within 24 hours of enableing it and may delete the object module where the code using it resides.

                       

                      This business of dropping references is fairly common.  I have had Excel and MS Access VBA applications drop  references to the PISDK and to some of the Windows libraries.  I have seen on Google where people have used VBE to set up references rather than relying on Excel to retain the settings.

                       

                      How is VBA able to cast early binding libraries and not late binding?  It seems that the mechanism to do it must be in the library.

                        • Re: Using IPIData2 interface with late binding

                          Do you know why the references keep getting dropped?

                           

                          Also, any way you can move from a VBA project to a .NET add-in? It would allow you to type-cast all you want, amongst several other benefits...

                            • Re: Using IPIData2 interface with late binding
                              DavidMFairchild

                              Steve,  I am not sure.  I have seen this issue many times over the years with a variety of different libraries including some from Microsoft.  In this case it may be because I am using PISDK version 1.3.8 and one of the primary users of this application has PISDK version 1.3.4.  But that's purely a guess.

                               

                              Switching everything to late binding seems to have resolved the  reference problem.  I just eliminated any functions that required the advanced interface and all is well now.

                               

                              This is a pretty extensive application and changing it to a C# plug-in would be quite time consuming.