3 Replies Latest reply on Apr 3, 2012 5:31 PM by andreas

    Plot a trend using an VB.Net AddIn

    ConditionMonitoring

      Im using the vb.net toolbar button addin to:

       

      1. Open a new pbDisplay

       

      2. then add a trend to the graph (which will eventually use info from a database but for the moment i am using dummy data that is manually entered into the code)

       

       

       

      I have created a VBA macro that was able to plot this dummy data but now i want to use this addin instead. However i am having trouble translating the vba code to vb.net code. The trouble arises when using the Class Trend and then adding this to the ActiveDisplay

       

      Any help would be greatly appreciated.

        • Re: Plot a trend using an VB.Net AddIn
          andreas

          Not sure that I understand the "manually entered into the code" part. Here is the code in dotnet (c# - but VB.NET should look almost the same, except no ; and some dim):

           
          PBObjLib.Display myDisplay = this.app.Displays.Add("MyDisp");
          PBObjLib.Symbol mySymbol = myDisplay.Symbols.Add(PBObjLib.pbSYMBOLTYPE.pbSymbolTrend);
          PBSymLib.Trend myTrend = (PBSymLib.Trend)mySymbol;
          myTrend.AddTrace("Sinusoid");
          

           

           

          can you share your VBA code to clarify the "manually entered into the code" part?

            • Re: Plot a trend using an VB.Net AddIn
              ConditionMonitoring

              Thanks, it works!
              that is the whole code I used in VB.NET with template for AddToolBar

               
               Private Sub AddInClicked(ByVal commandBarButton As PBObjLib.PBCommandBarButton, ByRef b1 As Boolean)
              
              
                      Dim newwindow As New PBObjLib.Display
              
                      newwindow = app.Displays.Add("test")
              
                      newwindow.Maximize()
                      newwindow.BackgroundColor = RGB(0, 0, 256)
              
                      Dim oSymbol As PBObjLib.Symbol
                      oSymbol = newwindow.Symbols.Add(PBObjLib.pbSYMBOLTYPE.pbSymbolTrend)
              
                      Dim oTrend As PBSymLib.Trend
                      oTrend = oSymbol
              
                      Dim sServer As String
                      Dim sTagName(12) as String
                      sServer = "\\***\"   (this is your PI tag site name)
              
                      sTagName(1) = "69PGA20CT001_XQ50"
                      sTagName(2) = "69PGC10AP001"
                      sTagName(3) = "69PGC10AP001_Bin"
                      sTagName(4) = "69PGC20AP001"
                      sTagName(5) = "69PGC20AP001_Bin"
                      sTagName(6) = "68LAC50CT008_XQ50"
                      sTagName(7) = "68LAC50CT009_XQ50"
                      sTagName(8) = "68LAC60CT008_XQ50"
                      sTagName(9) = "68LAC60CT009_XQ50"
                      sTagName(10) = "61MBL10CT001_XQ60"
                      sTagName(11) = "68PAB10CT001_XQ50"
                      sTagName(12) = "61MKA10CE600_XJ01"
              
                      With oTrend
              
              
                          .Name = "Test"
              
                          'set the position and size of the trend
              
                          .Top = 14784
              
                          .Left = -14511
              
                          .Width = 3573
              
                          .Height = 2400
              
                          'call the AddTrace function for every tag to be trended
                          For i = 1 To 12
                              .AddTrace(sServer & sTagName(i))
                          Next i
              
                          'this trend will display the previous 12 hours
                          .SetStartAndEndTime("*-30d", "*")
              
                          'set the title text
              
                          .TrendTitle = "Plot-0"
                          .MultipleScales = True
              
              
                      End With
              
              
                  End Sub