Button to populate current time in a field

kevsh
kevsh used Ask the Experts™
on
I am creating a form in R5 where I want to create a button that will automatically take the current date and time and display that information in a field (FieldB).  Than I want to take that time and subtract it agaisnt FieldA which would have an earlier time.  My goal is to take two time fields and calculate the time elapsed.  

Please help!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007

Commented:
Yo can certain use the @now function for this, but you may need to worry about refreshing the field accidentally.
You might consider setting it as create on compose, or as you said actuate it through a seperate button.

 I hope this helps !

Author

Commented:
Thanks, but how would I get that specific date value into a field?  Would the code reside in the button, saying something like "take @NOW and place in FieldB" or would it be in the field, saying something like "grab @now value from time button"
Commented:
The code for the button could be:

FIELD FieldB := @Now;
@All

Regards,

Scott
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Let the button code have Scotts formula.

Your last option of showing difference is a bit tricky because if you subtract two times it will give the value in seconds.

Even if you subtract dates you will have to divide the result with 86400 to have number of days since 86400 makes one day !

Just couple thoughts for you to go ahead further in your attempt.

:-)
Top Expert 2007

Commented:
I would also check out

http://www-10.lotus.com/ldd/sandbox.nsf

for tons of example of code and databases and solutions.

IN addition do a search on the EE site.

 I hope this helps !
Top Expert 2007

Commented:
I would also check out

http://www-10.lotus.com/ldd/sandbox.nsf

for tons of example of code and databases and solutions.

IN addition do a search on the EE site.

 I hope this helps !
I created a custom made solution for you... in LotusScript!

On a for I created 2 fields:
"Start" (your "FieldA"): Date time, showing day, month, year, hours, minutes and seconds
"Elapsed" (your FieldB"): DateTime, showing hours, minutes and seconds only.
There are no buttons!

Globals section on the form, under "(Declarations)":

Dim mySession As NotesSession
Dim myTimer As NotesTimer
Dim uiDoc As NotesUIDocument


Other Form events and subs:

Sub Postopen(Source As Notesuidocument)
     Set mySession = New NotesSession
     Set myTimer = mySession.CreateTimer
     Set uiDoc = Source
     Call ToggleTimer
End Sub

Sub Postmodechange(Source As Notesuidocument)
     Call ToggleTimer
End Sub

Sub ToggleTimer
     If uiDoc.Editmode Then
          ' fields available for update -> start timer
          If uiDoc.EditMode Then
               Call uiDoc.FieldSetText("Start", Cstr(Now)) ' update Start, or Elapsed might take an unexpected jump
          End If
          myTimer.Interval = 1 ' seconds
          myTimer.Enabled = True ' active
          On Event Alarm From myTimer Call TimerHandler
     Else
          ' fields not available for update -> stop timer
          myTimer.Enabled = False ' inactive
     End If
End Sub

Sub TimerHandler(Source As NotesTimer)
     Dim D0 As New NotesDateTime(uiDoc.FieldGetText("Start"))
     Dim D1 As New NotesDateTime(Cstr(Now))
     Dim Ddiff As Variant
     Ddiff = D1.LsLocalTime - D0.LsLocalTime
     If uiDoc.EditMode Then
          Call uiDoc.FieldSetText("Elapsed", Format$(Ddiff, "Long Time"))
     End If
End Sub


I think that's all you requested. A bit more even: whenever you switch to editmode (where I can update fields), it monitors/ records how long you stay there.
One note: in this code "Elapsed" gets updated every second. The timer-event works in seconds (not msec), so I can't speed it up if you want to!

(Been a great challenge!)

Commented:
I needed to do something similar in order to determine if an agent should run on a nightly basis. In the example below hpathname refers to a date field on a form that I was looking at through a view. In this case if the Date of the field on the form plus 5 days = Today's date, then I would execute some code.

Use all of the functions for minutes, seconds etc. to subtract for you situation instead of days.

If (Datevalue(hpathname) + 5  = Datevalue(Today))

Author

Commented:
Thanks again!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial