I have a form containing a Close button which runs various commands in Lotus Script. I want to include some formula I found on this website to calculate Days/Hours/Minutes in this button. I have tried the evaluate command but I can’t get the values to calculate. I know the formula works as I have it as a seperate Action at the moment for testing purposes.
Subject: Help with running Formula within Lotus Script
Post your code please…
Maybe you need to add uidoc or doc to the end of the Evaluate statement, e.g.
Eval=Evaluate(|@Function|,doc|)
Subject: RE: Help with running Formula within Lotus Script
Thanks a mill for that, I put a ,doc at the end of the Evaluate statement and I got the values calculated correctly.
Subject: RE: Help with running Formula within Lotus Script
Just a note here – it’s actually easier to do this is LotusScript than it is to do it in Formula Language.
A LotusScript Date variant is a number in the form of days.fraction from a base date and time of midnight (start of day) on December 31, 1899. (Why that date? Why not January 1, 1900, for instance? Joel Spolski explains how the base date was arrived at in Visual Basic for Applications, based on data that lived “everywhere” in Lotus 1-2-3 in an interesting article at joelonsoftware.com.)
Anyway, the upshot is that if you subtract one date from another in LotusScript (that’s Variants, not NotesDateTime objects), you are left with a number that’s still in the format “days.fraction”. Take the integer of that number, and you have the number of days. Multiply the fraction by 24. The integer portion is now the number of hours. Multiply the fraction by 60 and take the integer to get the number of minutes, and again for the seconds.
Function TimeDifferenceString(startTime As Variant, endTime As Variant) As String
Dim timeDiff As Double
Dim buildString As String
timeDiff = Abs(endTime - startTime)
buildString = Cstr(Int(timeDiff)) + " days, "
timeDiff = 24 * Fraction(timeDiff)
buildString = buildString + Cstr(Int(timeDiff)) + " hours, "
timeDiff = 60 * Fraction(timeDiff)
buildString = buildString + Cstr(Int(timeDiff)) + " minutes, "
timeDiff = 60 * Fraction(timeDiff)
buildString = buildString + Cstr(Round(timeDiff, 0)) + " seconds."
TimeDifferenceString = buildString
End Function