3 Replies Latest reply on Aug 28, 2013 1:43 PM by Marcos Vainer Loeff

    Create Labels with (hiperlink) to trends...

    rodolfome

      Hello,

       

      I trying to make some displays with 200 tags, and i need to add AdHoc Trend to each symbol... when the user clicks on the label, the processbook must open an AdHoc Trend with XYZ tag.

       

      Then i made a VB Function... to create a label... and calls it 200 times...

       

      Function createLabel(tagname As String, pTop As Integer, pLeft As Integer) As String
          Dim lbl As Text
          piServer = "\\pi01\"
          Set lbl = ThisDisplay.Symbols.Add(pbSymbolText)
          lbl.Contents = tagname
          lbl.BackgroundColor = -1
          lbl.LineColor = pbBlack
          lbl.Font.Name = "Arial"
          lbl.Font.Size = 12
          lbl.Top = pTop
          lbl.Left = pLeft + 60
      End Function

       

      so how i want to add "hiperlink" to each label... to open AdHoc Trend (with lbl.Contents as TAG)

       

      can i do that ? ^^

       

      regards, and sorry about the poor english.

        • Re: Create Labels with (hiperlink) to trends...
          dhollebeek

          I don't think PB Text symbols have any events (I'm sure there's no click event).  Have you considered using either a Microsoft or PB button and then alter the background, border, etc to look similar to a label?  Then you just have to write code to show the adhoc trend when the button is clicked ...

            • Re: Create Labels with (hiperlink) to trends...

              You can use the SelectedSymbols collection within the SelectionChange event, just grab the last element of the collection (the last symbol clicked) and run your code (but check you're not in build mode) to change a trend symbol trace, or show an adhoc trend.

                • Re: Create Labels with (hiperlink) to trends...
                  Marcos Vainer Loeff

                  Hello Rodolfo,

                   

                  Using the suggestions above, I have developed a sample code for you.

                   

                   

                   

                   

                   
                  Private Sub Display_Open()
                  
                  End Sub
                  
                  Private Sub Display_SelectionChange()
                  Dim myTextSymbol As Text
                      If (ThisDisplay.SelectedSymbols.Count > 0) Then
                          If (ThisDisplay.SelectedSymbols.Item(ThisDisplay.SelectedSymbols.Count).Type = 4) Then
                              Set myTextSymbol = ThisDisplay.SelectedSymbols.Item(ThisDisplay.SelectedSymbols.Count)
                              Call Label_Click(myTextSymbol.Contents)
                          End If
                      End If
                  
                  End Sub
                  
                  Public Sub createLabels()
                  
                  Call createLabel("sinusoid")
                  Call createLabel("cdt158")
                  Call createLabel("cdt160")
                  
                  End Sub
                  
                  Public Sub createLabel(tagname As String)
                      Dim lbl As Text
                      Set lbl = ThisDisplay.Symbols.Add(pbSymbolText)
                      lbl.Contents = tagname
                      lbl.BackgroundColor = -1
                      lbl.LineColor = pbBlack
                      lbl.Font.Name = "Arial"
                      lbl.Font.Size = 12
                      lbl.EnableScript = True
                      
                      
                  End Sub
                  
                  
                  Public Sub Label_Click(tagname As String)
                  
                  Dim CurrentNumberOfDisplays As Integer
                  CurrentNumberOfDisplays = Application.Displays.Count
                  Application.Displays.Add ("AdHoc Trend")
                  Call CreateTrend(tagname, "\\marc-pi2012\", CurrentNumberOfDisplays + 1)
                  End Sub
                  
                  Public Sub CreateTrend(sTagname As String, sServer As String, n As Integer)
                  
                  Dim oTrend As Trend
                  
                  Set oTrend = Application.Displays.Item(n).Symbols.Add(pbSymbolTrend)
                  With oTrend
                  .Name = "TestTrend1"
                  .Top = 14950
                  .Left = -14700
                  .Width = 1000
                  .Height = 750
                  .AddTrace sServer & sTagname
                  .SetStartAndEndTime Format(DateAdd("h", -12, Now), "dd-mmm-yy hh:nn:ss"), Format(Now, "dd-mmm-yy hh:nn:ss")
                  .TrendTitle = "Trend Example"
                  End With
                  
                  
                  
                  End Sub
                  

                   Let us know if you still have any questions,