14 Replies Latest reply on Dec 1, 2016 12:34 PM by AChatwin

    How to change a trend start and end time.

    AChatwin

      Hi All,
      Please see the code:

       

      Option Explicit
      Sub CommandButtonUpdateGraphs_Click()
      Dim Starttime As Variant
      Dim Endtime As Variant

       

      Starttime = ThisDisplay.Date1.Value & " " & ThisDisplay.Time1.Value
      Endtime = ThisDisplay.Date2.Value & " " & ThisDisplay.Time2.Value
      MsgBox Starttime
      MsgBox Endtime

      TrendB1WingValvePosition.SetTimeRange Starttime, Endtime

      'This doesn't work
      TrendB1WingValvePosition.SetTimeRange Starttime, Endtime

      'This doesn't work
      End Sub

       

      The Msgbox are correctly reading the output of the time selection boxes but I am unable to enter the correct details for a trend to change its starting and end point. This would make it easier for the guys to be able to change all graphs at once.


      Any one able to indicate what I am doing wrong. This doesn't work. Some assistance would be great.

       

      Regards,

       

      Alex

        • Re: How to change a trend start and end time.
          Asle Frantzen

          Hi

           

          The code should work, so I'm suspecting the input values for the timestamps to be the issue.

           

          I tried the following, just to make sure I had the correct timestamp format:

           

          Dim r As Boolean
          r = Trend2.SetTimeRange(Trend1.StartTime, Trend1.EndTime)
          MsgBox r
          

           

          Please try that and make sure it returns true. If not, it's not able to set the time range.

          1 of 1 people found this helpful
          • Re: How to change a trend start and end time.
            AChatwin

            Firstly,

             

            I would like this opportunity to thank the great customer support I have just received from Greggor on this issue as well as asking some other pretty difficult questions.

             

            The issue with pulling the data from DT Picker as a variable seems to be a function of the Regional Settings of the computer the Pi Process Book is running. Therefore, in order to develop a robust PI Processbook Display for someone else to use, Greggor has made me aware that DTPicker has some child properties of Day / Month / Year / Hour / Minute and Second as a variable separately. Nice one!!

             

            Starttimehour = DTPicker.Hour.value


            Therefore, for this it would be a caser of pulling out each as a variable and building up the expression afterwards.

             

            I will post after I have made it some code that shows this so that all can see or comment on what I have done with it. More to follow.

             

             

            Cheers for the feedback!!

             

             

            Alex

            1 of 1 people found this helpful
            • Re: How to change a trend start and end time.
              knightk

              I wouldn't use starttime and endtime as variable names because these already exist in Processbook. The time in a date picker is always dated the current day so if you take the current day (date) from your time value and add the date value you should end up with a full timestamp, this can be formatted so it looks like a PI timestamp, and you should be able to set the trend start end time using something like the below?

               

              varStartTime = Format(Date1.Value + (Time1.Value - Date), "dd-mmm-yy hh:mm:ss")
              varEndTime = Format(Date2.Value + (Time2.Value - Date), "dd-mmm-yy hh:mm:ss")

              MsgBox (varStartTime)
              MsgBox (varEndTime)

              Trend1.SetTimeRange varStartTime, varEndTime

               

              edit: probably also a good idea.....

               

              if varEndTime > varStartTime then

                   Trend1.SetTimeRange varStartTime, varEndTime

                   else

                   msgbox("Start time must be before End time")

              end if

              2 of 2 people found this helpful
              • Re: How to change a trend start and end time.
                AChatwin

                Here are the two solutions. Just for everyone's reference. I have had a bit of fun doing this ;-).

                Start date is in DTPicker1 called Date1

                End Date is in DTPicker2 called Date2

                Start time is in DTPicker3 called Time1

                End Time is in DTPicker4 called Time2

                Cheers,

                 

                Alex

                 

                Option Explicit
                Sub CommandButtonUpdateGraphs_Click()

                Dim TrndStartTime As String
                Dim TrndEndTime As String

                TrndStartTime = Format(Date1.Value, "dd-mmm-yyyy hh:mm:ss")
                TrndEndTime = Format(Date2.Value, "dd-mmm-yyyy hh:mm:s")

                MsgBox (TrndStartTime)
                MsgBox (TrndEndTime)

                If TrndStartTime < TrndEndTime Then
                     TrendB1WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                     TrendB2WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                     TrendB3WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                     TrendB4WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                     TrendB5WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime

                     TrendK12WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                     TrendK13WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                     TrendK14WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                     TrendK15WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                Else
                     MsgBox ("Start Time must be before End Time")
                End If

                End Sub

                 

                Sub CommandButtonUpdateGraphs2_Click()

                Dim TrndStartYear, TrndStartMonth, TrndStartDay As String
                Dim TrndEndYear, TrndEndMonth, TrndEndDay As String
                Dim TrndStartTime, TrndEndTime As String
                Dim Mth As Integer
                Dim Monthlookup(12) As String

                 

                     Monthlookup(1) = "Jan"
                     Monthlookup(2) = "Feb"
                     Monthlookup(3) = "Mar"
                     Monthlookup(4) = "Apr"
                     Monthlookup(5) = "May"
                     Monthlookup(6) = "Jun"
                     Monthlookup(7) = "Jul"
                     Monthlookup(8) = "Aug"
                     Monthlookup(9) = "Sep"
                     Monthlookup(10) = "Oct"
                     Monthlookup(11) = "Nov"
                     Monthlookup(12) = "Dec"

                 

                Mth = Date1.Month
                TrndStartMonth = Monthlookup(Mth)
                Mth = Date2.Month
                TrndEndMonth = Monthlookup(Mth)

                 

                TrndStartYear = Date1.Year
                TrndStartDay = Date1.Day
                TrndEndYear = Date2.Year
                TrndEndDay = Date2.Day

                 

                'luckily code here works ok for 01 or 1 for day. This has zero effect on not making the trend work.
                TrndStartTime = TrndStartDay + "-" & TrndStartMonth + "-" & TrndStartYear
                TrndEndTime = TrndEndDay + "-" & TrndEndMonth + "-" & TrndEndYear

                 

                If (Date1.Value + Time1.Value) < (Date2.Value + Time2.Value) Then
                    TrendB1WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                    TrendB2WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                    TrendB3WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                    TrendB4WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                    TrendB5WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                   
                    TrendK12WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                    TrendK13WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                    TrendK14WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                    TrendK15WingValvePosition.SetTimeRange TrndStartTime, TrndEndTime
                Else
                    MsgBox ("Start Time must be before the End Time")
                End If

                End Sub