LOTUSSCRIPT 言語
例 1:
Sub Initialize
Dim Sess As New NotesSession
Dim Doc As NotesDocument
Dim Count As NotesItem
Set Doc = Sess.SavedData
Set count = Doc.GetFirstItem("WebHits")
If count Is Nothing Then
Set count = New NotesItem(Doc, "WebHits", 0)
End If
count.Values = count.Values(0) + 1
Call Doc.Save(True,False)
End Sub
2 番目の例は、例 1 で示された問題を CodeLock を使用して回避する方法について示しています。安全なロックを作成して確認した後、カウントを読み取って変更します。作業が終わったらこのロックを解除します。
例 2:
Dim Status As Integer
Dim LockID As Integer
Dim others As Integer
' Creating a Lock ID or getting the Lock ID
' For the event of "WebSiteHits"
LockID = Createlock("WebSiteHits")
' Infinite loop that can only be exited
' when this agent has a successfull
' lock.An unsuccessfull lock means
' that this agent is presently being
' run by someone else.
Do While True
If Codelock(LockID) Then
Exit Do' We finally have a lock, exiting Loop
Loop
' Once completed, release and
' destroy this lock so another
' run of this agent can continue.
Status = CodeUnlock(LockID)
Status = DestroyLock(LockID)