8 Replies Latest reply on May 1, 2017 2:15 AM by dhollebeek

    Hello everyone, I need your help to add a trend in a VBA6 form

    Castillo1979

      The code in processbook would be this:

       

      Sub CreateTrend()

       

      'PB Symbol object

      Dim oTrend As Trend

      Dim sServer As String

      Dim sTagName, sTagName1 As String

       

      'Server_name_here

      sServer = ""

       

      'tag_name_here

      sTagName = "10GHF56CF001.ZQ01"

      sTagName1 = "10LBA20CP901.XQ01"

       

      'add a trend object to the Symbols collection

      'the Add function will return a reference to the trend object

      'if successful

        Set oTrend = ThisDisplay.Symbols.Add(pbSymbolTrend)

                   

             With oTrend

                  .Name = "TestTrend1"

                  .Top = 14950

                  .Left = -14700

                  .Width = 1000

                  .Height = 750

                 

                  'call the AddTrace function for every tag to be trended

                  .AddTrace sServer & sTagName

                  .AddTrace sServer & sTagName1

                 

                  'this trend will display the previous 12 hours

                  .SetStartAndEndTime Format(DateAdd("h", -24, Now), _

                   "dd-mmm-yy hh:nn:ss"), Format(Now, "dd-mmm-yy hh:nn:ss")

                  

                   'set the title text

                    .TrendTitle = "Trend Example"

           End With

       

      End Sub

       

      But this code does not work in VBA6, someone could help me?

        • Re:  Hello everyone, I need your help to add a trend in a VBA6 form
          Kenji Hashimoto

          Is VBA6 means Visual Basic 6?

          VB6 is really old technology. Do you have specific reason to use VB6?

          Adding the code shows Dim oTrend As Trend. This is PI ProcessBook object name. It works only for PI ProcessBook VBA.

          If you want to create custom application by VB6, I think you need to use PISDK, PI API etc.... ( AFSDK does not work with VB6...)

          I recommend to use the latest version of VB.net or C# + AFSDK.

          1 of 1 people found this helpful
          • Re:  Hello everyone, I need your help to add a trend in a VBA6 form
            Rick Davin

            Hi Raúl,

             

            I agree with Kenji in that I question why you would use VB6 to start a new forms based project.  That said, here's things to consider about your posted code:

             

            What are the specific error messages you are seeing?  Is it a compiler or run-time error?

             

            Does your project have the correct references to the PI-ProcessBook Type Library (for PBObjLib) and PI-ProcessBook Symbol Library (for PBSymLib)?  These libraries are automatically referenced within ProcessBook VBA but would need to be explicitly added to a VB6 project.

             

            You may have to add references to PISDK, PITimeServer, and PISDKCommon type libraries.  These are neither added automatically by ProcessBook VBA or VB6.

             

            I think the object ThisDisplay may lack context in VB6, whereas its automatically set by ProcessBook VBA.  When you debug does ThisDisplay show as Nothing?  You will need to create VB6 objects to hold your ProcessBook Application instance, the Workbook instance (if needed), as well as the desired Display instance.

             

            The data type for variable sTagName is NOT a String.  It is a Variant.  I'd recommend variable declarations on separate lines but if you insist on a one-liner it should be:

                 Dim sTagName As String, sTagName1 As String

             

            The variable sServer is set to the empty string.  Is this the way it is in your code or is this your attempt to obfuscate your settings?  If it truly is an empty string, I see no reason to have it in the sub since it adds no value. If you do have a value that you just don't want us to see, then the you need to insert backslashes appropriately in your AddTrace calls.

            2 of 2 people found this helpful
              • Re:  Hello everyone, I need your help to add a trend in a VBA6 form
                Castillo1979

                Thanks for the reply Rick, and I comment, VB6 is used because it is what the company has for the moment, but I want to update vb.net soon, as Kenji sues me, but I commit them I have added all the libraries and I use The following code and is true Rick where I have problems is in the thisDisplay object, I do not know how to apply it in VB.

                 

                 

                 

                Sub CreateTrend()

                'PB Symbol object

                Dim oTrend As PITrend

                Dim sServer As String

                Dim sTagName As String

                Dim ThisDisplay As Display

                 

                'Server_name_here

                sServer = "172.18.42.9"

                 

                'tag_name_here

                sTagName = "10GHF56CF001.ZQ01"

                 

                   'PItrens2 as OLE "PI Trend Excel"

                   Set oTrend = PITrend2.Symbols.Add(pbSymbolTrend) 'The error is here

                     

                  

                      

                       With oTrend

                            .Name = "TestTrend1"

                            .Top = 14950

                            .Left = -14700

                            .Width = 1000

                            .Height = 750

                           

                            'call the AddTrace function for every tag to be trended

                            .AddTrace sServer & sTagName

                           

                            'this trend will display the previous 12 hours

                            .SetStartAndEndTime Format(DateAdd("h", -12, Now), _

                             "dd-mmm-yy hh:nn:ss"), Format(Now, "dd-mmm-yy hh:nn:ss")

                            

                             'set the title text

                              .TrendTitle = "Trend Example"

                     End With

                 

                End Sub

                  • Re:  Hello everyone, I need your help to add a trend in a VBA6 form
                    Rick Davin

                    Hi Raúl,

                     

                    As I mentioned yesterday: I think the object ThisDisplay may lack context in VB6, whereas its automatically set by ProcessBook VBA.  When you debug does ThisDisplay show as Nothing?  You will need to create VB6 objects to hold your ProcessBook Application instance, the Workbook instance (if needed), as well as the desired Display instance.

                     

                    To set an Application instance you can either use:

                    Dim pbApp As PBObjLib.Application

                    Set pbApp = CreateObject("PIProcessBook.Application")

                     

                    Or simply use:

                    Dim pbApp As New PBObjLib.Application

                     

                    Then you would have a ProcBook object:

                    Dim pBook As ProcBook

                    Set pBook = pbApp.ProcBooks.Open("directory and file path to your procbook.PIW")

                     

                    Open a specific display in the ProcBook takes an Entry object and then a Display:

                    Dim myEntry As PBObjLib.Entry

                    Dim myDisplay As PBObjLib.Display

                     

                    'Open the Display

                    Set myEntry = pBook.Entries.Item("desired display name")

                    myEntry.Execute (False)

                     

                    'Get the display that was opened

                    Set myDisplay = myEntry.Application.ActiveDisplay

                     

                    All these mechanics are done for you by ProcBook VBA.  But since you are using VB6, you must do it yourself.  Now instead of using ThisDisplay, you would use myDisplay instead:

                    Set oTrend = myDisplay.Symbols.Add(pbSymbolTrend)

                     

                    That should get you past the current error.  But there is a bug later in your code with this line:

                    .AddTrace sServer & sTagName

                     

                    Because the concatentation of sServer and sTagName would result in the literal string "172.18.42.910GHF56CF001.ZQ01".  You probably want that to be "\\172.18.42.9\10GHF56CF001.ZQ01" so you will need to put the backslashes in there as well.

                      • Re:  Hello everyone, I need your help to add a trend in a VBA6 form
                        Castillo1979

                        Hi Rick. Thank you very much for the code, but I comment you almost work, make some changes to the code to work the truth, but it is not what I need, because the code runs the proccess book, opens a screen and finally a trend, Of the tag I send, what I need if it is possible, that this trend is displayed inside the VB6 form, I hope and you can help me I will keep trying.

                        Sub CreateTrend()

                         

                        Dim oTrend As PBSymLib.Trend

                        Dim sServer As String

                        Dim sTagName As String

                         

                        'PB Symbol object

                        Dim objProcessBook As New PBObjLib.Application

                                   'Dim objProcessBook As PBObjLib.Application

                                   'Set objProcessBook = CreateObject("PIProcessBook.Application.2")

                         

                        Dim pBook As ProcBook

                        Set pBook = objProcessBook.ProcBooks.Open("C:\Users\44980425\Desktop\Ronda Operador Access PI\TREN b.PIW")

                         

                        Dim myEntry As PBObjLib.Entry

                        Dim myDisplay As PBObjLib.Display

                         

                        Set myEntry = pBook.Entries.Add("wer2")   

                        myEntry.Execute (True)

                         

                        Set myDisplay = myEntry.Application.Displays.Add("Trend")

                         

                        'Server_name_here

                        'sServer = "172.18.42.9"

                         

                        'tag_name_here

                        sTagName = "10GHF56CF001.ZQ01"

                         

                           Set oTrend = myDisplay.Symbols.Add(pbSymbolTrend)

                            oTrend.Maximize True

                            oTrend.BackgroundColor = RGB(0, 0, 256)

                         

                            With oTrend

                         

                                    .Name = "TestTrend1"

                                    .Top = 14950

                                    .Left = -14701

                                    .Width = 1974

                                    .Height = 1085

                                 

                                     .AddTrace sServer & sTagName

                                  

                                     .SetStartAndEndTime Format(DateAdd("h", -24, Now), _

                                     "dd-mmm-yy hh:nn:ss"), Format(Now, "dd-mmm-yy hh:nn:ss")

                                  

                                      .TrendTitle = "Trend Example"

                         

                             End With

                         

                        End Sub

                         

                         

                         

                        Again thank you very much.

                        regards

                        Raul Castillo

                      • Re:  Hello everyone, I need your help to add a trend in a VBA6 form
                        gregor

                        Hello Raúl,

                         

                        ProcessBook is a bit old fashion but the fact you are asking about using PBTrend control in a custom application indicates that there's no concern about the look of ProcessBook. I am curious about the motivation for using PBTrend in a custom application instead of using PI ProcessBook. Can you share any related information?

                          • Re:  Hello everyone, I need your help to add a trend in a VBA6 form
                            Castillo1979

                            Hi Gregor Beck

                            Of course I can share information, I comment you currently work in a power plant, the PI proccess book system we use as an auxiliary and data acquisition system, so we require the power plant operator, turn by turn to analyze Specific trends which change depending on the requirements of the Chief or the needs of the plant for which we require an external program that uses trends and where you can place comments, we currently use for that task microsoft excel but not very friendly and it is very slow.

                            regards
                            Raúl Castillo Peña

                      • Re:  Hello everyone, I need your help to add a trend in a VBA6 form
                        dhollebeek

                        The only way to embed ProcessBook inside of an application is to use OLE embedding (i.e. ActiveX).  However, we've had numerous reports that OLE is somewhat problematic on newer operating systems and it's a security concern as well, so I wouldn't recommend that.  The best way to do what you are trying to do would be to run ProcessBook as an application and then create either VBA or a custom add-in that allows the operator to add comments and perform whatever other operations you need.

                         

                        Thanks,