8 Replies Latest reply on Mar 24, 2010 12:00 PM by andreas

    Manipulating time strings in Processbook VBA

    AlistairFrith

      We want to be able to convert the timestamp strings provided to the Trend TimeRangeChange event into a system time, so we can compare it. The reason we are doing this is so we can show the display's 'end time' at the top of the display and have it indicate whether the display is showing current data or historical. Essentially, we expect the code to look something like this:

       

      Private Sub Logo_Trend_TimeRangeChange(ByVal StartTime As String, ByVal EndTime As String)
         
      dim et as Date
          dim diffSecs as integer

          et = PIDateToSystemDate(EndTime)      ' <-- ** Essentially, I want to know what function to use here **
          diffSecs = DateDiff("s", EndTime, now())

          if diffSecs > 30 then
         
          'viewing historic time
              TimeStamp_Text.BackgroundColor = 3844043
         
          TimeStamp_Text.Contents = ("Historic: " & Format(et, "dd/MM/yyyy HH:mm:ss"))
          else if diffSecs < -30 then
         
          'viewing future time (probably no data but at least they will know why!)
              TimeStamp_Text.BackgroundColor = 3844043
         
          TimeStamp_Text.Contents = ("Future: " & Format(et, "dd/MM/yyyy HH:mm:ss"))
          Else
              'viewing current time
         
          TimeStamp_Text.BackgroundColor = -1
              TimeStamp_Text.Contents = ("Current: " & Format(et, "dd/MM/yyyy HH:mm:ss"))
          End If
      End Sub

       

      What is the correct function to use to convert a PI time string into the Date format? Also, are we doing anything stupid here?

       

      --- Alistair

        • Re: Manipulating time strings in Processbook VBA
          AlistairFrith

          I think I have a solution, except for the minor problem that it doesn't work! In the SDK documentation for the PITimeServer DLL, it has an example of using the PITimeServer.PITime class:

           

          Dim pt1 As New PITime
          pt1.LocalDate = Text1.Text

           

          so from that I sumised that PITime.LocalDate should be able to parse a text string. I then coded this:

           

          Private Sub Logo_Trend_TimeRangeChange(ByVal StartTime As String, ByVal EndTime As String)

              Dim dEndTime As PITimeServer.PITime
              Dim diffSecs As Integer

           

              Set dEndTime = New PITimeServer.PITime
              dEndTime.LocalDate = EndTime                        '<-- Here it goes 'bang'
              diffSecs = DateDiff("s", dEndTime.LocalDate, Now())

           

          but on line 7 I get "Run time error 13: Type Mismatch". Why?!?!? EndTime at this point is "18/08/2009 08:27:12.619", which is exactly the same format as the example in the helpfile.

           

          --- Alistair.