4 Replies Latest reply on Jul 24, 2015 2:39 PM by jewboy20

    VBA novice here: need time range change

    jewboy20

      VBA novice here: After some work, I have two tags that return timestamps.  I need a button that sets the time range for they display as starting at "Tag 1" and ending at Tag 2".  Then I need a button that returns the time range for the display back to the default.  Thanks

        • Re: VBA novice here: need time range change
          kfong

          Hi Jordan,

          Thanks for your post.  You may find this document on VBA and Processbook helpful: https://techsupport.osisoft.com/Downloads/File/a413616e-48bb-44ba-a368-38fe6ddbf714.  I perused some other PI Square threads and I think that this function may be useful.

           

          Private Sub DTPicker1_Change()

              ThisDisplay.SetTimeRange Format(DTPicker1.Value - 1, "dd-MMM-yyyy 06:50"), Format(DTPicker1.Value, "dd-MMM-yyyy 06:50")

          End Sub

          • Re: VBA novice here: need time range change
            dng

            Hi Jordan,

             

            What data type is your tag that return timestamp (e.g. string, timestamp)? What symbol do you used to display these tag values in PI ProcessBook? In the following example, I added two Value symbols (Value1 and Value2) to display the value of a string tag (which give timestamps in the format of 11-Mar-2015 00:00:00). The VBA code for the two buttons is as follow:

             

            Private Sub btnSetTime_Click()
                Dim vrDate As Variant
                Dim vrStatus As Variant
                Dim startTime As Variant
                Dim endTime As Variant
                Dim setTime As Boolean
                Dim syms As Symbols
                Dim sym As Symbol
               
                startTime = Value1.GetValue(vrDate, vrStatus)
                endTime = Value2.GetValue(vrDate, vrStatus)
               
                Set syms = ThisDisplay.Symbols
               
                For Each sym In syms
                    If (StrComp(sym.Name, Value1.Name) <> 0) Or (StrComp(sym.Name, Value2.Name) <> 0) Then
                        setTime = sym.SetTimeRange(startTime, endTime)
                    End If
                Next
            End Sub
            
            
            Private Sub btnRevert_Click()
                ThisDisplay.Revert
            End Sub
            

             

            Note that there is no error handling in the above code. The reason I'm excluding Value1 and Value2 from SetTimeRange is because the value might change if their timestamps change (I'm assuming you always want the latest value for those timestamps tag). Hope it helps.

             

            FYI, I have moved this thread to PI Developers Club > PI Visualization Development for further discussion.

            • Re: VBA novice here: need time range change
              dng

              Hi Jordan,


              Did any of the above proposed solution work for you? If so, please mark it as correct answer; if not, please let us know if you have any additional questions, or share what you did to resolve the issue. Thanks!

                • Re: VBA novice here: need time range change
                  jewboy20

                  Sorry it took so long to reply.  A combination of the two solutions above worked for me.  I was able to set the time range for my trends using Keith's method.  "ThisDisplay.Revert" did not work for me, so I had to use a version of your "ThisDisplay.Symbols" code to set the time range back to the default (*-1h, *) time range.  Thanks for your help!