Examples: NotesTimer class

This example maintains and reports the elapsed time since a document is opened, unless the user disables the timer. The example has several scripts.

  • These declarations are in the (Globals) (Declarations) script for the form. The variable elapsedTime is used by various objects on the form. The NotesTimer object elapsedTimer must be in effect during the execution of a number of scripts on the form.
    Dim elapsedTime As Integer
    Dim elapsedTimer As NotesTimer
    %INCLUDE "lsconst.lss"
  • When a document based on this form opens, the NotesTimer object is created with an interval of one second. An event handler for the Alarm event of the object is established.
    Sub Postopen(Source As Notesuidocument)
      Set elapsedTimer = New NotesTimer(1, _
      "Elapsed time since opening document")
      elapsedTime = 0
      On Event Alarm From elapsedTimer _
      Call elapsedTimerHandler
    End Sub
  • This user code is the event handler specified in the preceding On Event statement. It simply increments the global variable by 1 each time it is called.
    Sub elapsedTimerHandler(Source As NotesTimer)
      elapsedTime = elapsedTime + 1
    End Sub
  • This script is for a button on the form. The script displays the time accumulated in the global variable.
    Sub Click(Source As Button)
      Dim etime As Integer
      Dim minutes As Integer
      etime = elapsedTime
      If etime < 60 Then
        Messagebox etime & " second(s)",, _
        "Elapsed time since opening document"
      Else
        minutes = 0
        Do While etime > 59
          minutes = minutes + 1
          etime = etime - 60
        Loop
        Messagebox minutes & " minute(s), " _
        & etime & " second(s)",, _
        "Elapsed time since opening document"
      End If
    End Sub
  • This script queries the Enabled property of the NotesTimer object and toggles it if the user wants to.
    Sub Click(Source As Button)
      If elapsedTimer.Enabled Then
        If Messagebox _
        ("Do you want to disable the timer?", _
        MB_YESNO + MB_ICONQUESTION, _
        "Elapsed timer is enabled") = IDYES Then
          elapsedTimer.Enabled = False
        End If
      Else
        If Messagebox _
        ("Do you want to enable the timer?", _
        MB_YESNO + MB_ICONQUESTION, _
        "Elapsed timer is disabled") = IDYES Then
          elapsedTimer.Enabled = True
        End If
      End If
    End Sub