Why Display.SetTimeRange doesn't seem to work (even though it does)

Blog Post created by dhollebeek on Mar 8, 2017

I thought I'd put up a note about this one since it's one of the more common questions that have gotten about VBA through tech support over the years.  In fact, a question like this is one of the first tech support cases that ever got escalated to me back when I was the junior developer on the ProcessBook team (which was quite a while ago).


Display.SetTimeRange works the same as the old Time Range Toolbar.  For those of you who have used ProcessBook for years, you will remember the small toolbar that was used prior to ProcessBook 3.2.  This toolbar is now hidden for new installations, though it is still available in View->Toolbars...

This has been replaced by the newer Time Range and Playback Toolbar: 

Besides the added functionality.  One of things we changed when we created the new toolbar is that it affects all symbols no matter what, since the previous behavior was confusing.  So what, you may ask is the previous behavior (which Display.SetTimeRange still uses)?


This is actually a feature.  The old toolbar and Display.SetTimeRange only affect the selected symbols on a display.  If there are no selected symbols, then it applies to everything.  This way you have the option of either setting the time range for a single symbol, a set of symbols, or the entire display.  What typically ends up happening though is that there is a button on the display that calls VBA which then calls Display.SetTimeRange.  In this case, the button gets selected when you click on it, so the the buttons time range is changed (which doesn't do anything because buttons don't have time ranges).  Of course there are other cases where people call Display.SetTimeRange while there are symbols selected which has the same affect.


So, if you want to set the time range for an entire display, here's the code to do that:



    ThisDisplay.SetTimeRange "*-8h", "*"


The code in the newer Time Range and Playback Toolbar does something similar (it uses the ProcessBook Automation Model too).  However, it stores the list of selected symbols and then restores the selections after the time range is changed.  I'll leave it as a learning exercise to figure out how to do that.


Feel free to add comments below if I have managed to confuse you by this point...