You may have better luck with trend.SetTimeRange. For example,
ThisDisplay.Symbols("Trend1").SetTimeRange "*-2h", "*"
Instead, ThisDisplay.SetTimeRange seems to only change the time range if you first click on a symbol, and then shift-click the macro button.
Calling SetTimeRange against the actual symbol gives finer control. Note this will only change the (run-time) time range. If the display is reopened, it will revert to the configured time range. To change the configured time range, use SetStartAndEndTime.
Although I'm not sure how the details of the values/stats you want to show or format, I'm wondering if some of them could be performed using multistate symbols instead of custom coding.
What do you mean by "it does not seem to be functional"?
Your current code seems to have the timestamps both at midnight of the same day. For example, you should be able to get it to work with either:
ThisDisplay.SetTimeRange Format(StartTime.Value, "dd-MMM-yyyy hh:mm"), Format(EndTime.Value, "dd-MMM-yyyy hh:mm")
or even simply,
ThisDisplay.SetTimeRange Now - 0.5, Now
Thank you both for your advice. I was able to get the following code to work-- although it seems to only work for plots and not pi calculations. Here's the code in case it helps out anyone else:
Private Sub Update_Time_Range()
Dim Start_Time As Date
Dim End_Time As Date
Start_Time = Format(DTPicker1, "MM/dd/yyyy HH:mm")
End_Time = Format(DTPicker2, "MM/dd/yyyy HH:mm")
If Start_Time = End_Time Then
Dim Trend As Symbol
For Each Trend In ThisDisplay.Symbols
If Trend Type = pbSYMBOLTYPE.pbSymbolTrend Then
Call Trend.SetStartAndEndTime(Start_Time, End_Time)