4 Replies Latest reply on Jun 20, 2016 7:33 PM by wling1

    How can I change the time display of the current PI Tag values in a Processbook display through VBA?

    wling1

      Hi all,

       

      I have a Processbook display with some VBA coding in it. Part of my code involves changing the PI Tag used in value objects based on what is selected in a Combobox. When I change the view time or move the time slider back in time and then select a different Combobox selection, the values default back to the current time. I am looking for a way to have the time that is currently displayed stay whenever I make a different selection in the Combobox.

       

      Any help would be greatly appreciated and if this doesn't make sense I can try and clarify more!

        • Re: How can I change the time display of the current PI Tag values in a Processbook display through VBA?
          John Messinger

          Hello Wyatt,

           

          I've made some assumptions here, mainly that your display only contains single value objects (no trends). This being the case, in your combo box Change() event handler, you can capture the start and end times of the Display (even though a display does not really have a time range), and then re-apply this after making your change from the combo box selection. A simple example as follows:

           

          Private Sub cboSelector_Change()
          
              Dim sym As Value
              Dim endTime As Variant
              
              endTime = ThisDisplay.endTime
              
              Set sym = ThisDisplay.Symbols("valTarget")
              sym.SetTagName (cboSelector.Value)
              ThisDisplay.SetTimeRange endTime, endTime
              
          End Sub
          

           

          The display object will return an empty StartTime property, but when you use SetTimeRange you can't pass an empty string for the start time, so my workaround was to pass in the previously read end time twice.

          Going back to my assumption at the beginning, if you have a trend on the display, that will effectively set the time range for the display, and you could make use of that if needed. But this example will work when there are only symbols on the display that return a single value (Bars, Values, Multistates).

           

          Regards,

          John

          1 of 1 people found this helpful
            • Re: How can I change the time display of the current PI Tag values in a Processbook display through VBA?
              wling1

              Hi John,

               

              Thanks for your response. Your assumptions are correct in that I just have value objects with no trends. I tried implementing your code, but it looks like it returns the now time format ("*") for the endTime variable (line 6 of your code) despite my display time bar set to show a date from a year ago. I'm curious as to what dictates the end time of the display, since it looks like the time bar does not have influence on that.

                • Re: How can I change the time display of the current PI Tag values in a Processbook display through VBA?
                  John Messinger

                  Hi Wyatt,

                   

                  Technically a display has no time range. Value objects by default show tag values relative to the current time (snaphot values). When a trend is present on the display, it will set the time range for a display, and any value objects would show their values relative to the end time of the trend object. If you add a trend to your display, and then making sure no symbols are selected, use the time navigation buttons on the standard toolbar to move one time period back, you should see the value object timestamps move relative to the trend end time. Without the trend, the time navigation buttons won't have any effect.

                  On the sample display with the code I posted previously, I have the following objects:

                  In this screenshot, the value object shows the current snapshot value for my tag. If I select the Time Range button, only the End time is editable for me:

                   

                  Changing this to *-8 Hour will set the Value object to the nearest archive value for my tag to the selected time:

                   

                  At this point, if I were to run my code, I should see in my debugger that the Display.endTime property is set to the Value object's time:

                   

                  My Value object has now been updated with the new tag selection, and the time is close to the same as the previously captured time:

                   

                  This will work regardless of the number of value objects on my display. The key is to change the 'time range' before changing the selection via the combo box and verify that the value timestamp is correct (ie, relative to the selected end time).

                  As you mentioned  your "display time bar set to show a date from a year ago", can you confirm if this is the Time Range and Playback Toolbar add-in? If so, this code will still work, so long as the 'end time' part of the slider is set to a date in the past. Perhaps you could post a screenshot to show the configuration you have?

                   

                  Regards,

                  John

                  2 of 2 people found this helpful