例: Remove method (NotesAgent - LotusScript®)

  1. 次のスクリプトは、現在のデータベースから CalculateTotals エージェントを削除します。
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Set db = session.CurrentDatabase
    Forall a In db.Agents
      If ( a.Name = "CalculateTotals" ) Then
        Call a.Remove
      End If
    End Forall
  2. 次のスクリプトは、現在実行中のエージェントを削除します。エージェントの実行が終了した時点で、エージェントはデータベースから削除されます。
    ' Self-destructing agent created 08/18/95 by N. Allen
    Dim session As New NotesSession
    Dim agent As NotesAgent
    Set agent = session.CurrentAgent
    Call agent.Remove
  3. 次のスクリプトは現在のデータベースで現在のユーザーが所有する無効なエージェントを検索し、ユーザーに削除するかどうかを問い合わせます。ユーザーが削除を指定すると、スクリプトはデータベースからエージェントを削除します。

    このスクリプトは、現在のユーザーが所有する無効なエージェントを NotesAgent 型の配列で保持します。この配列は 10 個の要素を持つ配列として宣言されています。

    Sub Click(Source As Button)
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim agentArray( 1 To 10 ) As NotesAgent
      Dim count As Integer
      Dim r As String
      Set db = session.CurrentDatabase
      count = 0
      ' find agents owned by current user and disabled
      Forall a In db.Agents
        If ( a.Owner = session.UserName ) And _
        Not ( a.IsEnabled ) Then
          count = count + 1 
          Set agentArray( count ) = a
        End If
      End Forall
      r = Inputbox$( "You have " & count &  _
      " disabled agents. Delete them?" )
      If ( r = "yes" ) Or ( r = "y" ) Then
        ' go through each agent that's owned by current  
        ' user and disabled
        Forall b In agentArray
          Call b.Remove
        End Forall
      End If
    End Sub