私はこのコードを書きました。はるかに簡単です...
フィールド 'StartTime' および 'EndTime': 日付/時刻を入力し、Calendar/Time コントロールを使用して、時刻のみを表示するように設定します。「値の変更後に Exiting/OnChange イベントを実行する」プロパティを確認します。Exiting イベントは次のようになります。
Sub Exiting(Source As Field)
Call UpdateDuration()
End Sub
フィールド「期間」: 編集可能なテキスト フィールドですが、非表示です。
フィールド「dspDuration」: 表示テキスト フィールド用に計算されます。値は単なる「期間」です (引用符なし)。
次に、フォームのグローバル セクションに次のコードを追加します。
Sub UpdateDuration()
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim starttime As NotesDateTime
Dim endtime As NotesDateTime
Dim duration As Integer
Set uidoc = ws.CurrentDocument
'*** Exit if not both times are entered
If uidoc.FieldGetText("StartTime") = "" Then
Exit Sub
Elseif uidoc.FieldGetText("StartTime") = "" Then
Exit Sub
End If
'*** Calculate duration in seconds and update field
Set starttime = New NotesDateTime( uidoc.FieldGetText("StartTime") )
Set endtime = New NotesDateTime( uidoc.FieldGetText("EndTime") )
duration = endtime.TimeDifference( starttime )
Call uidoc.FieldSetText("Duration", Cstr(duration) )
Call uidoc.Refresh()
End Sub
それでおしまい。簡単ですね。出力 (デュレーション) を変更したい場合は、簡単に変更できます。おそらく、60 で割って分単位に変更できます。
