Cardbox Talk


CardboxForumsCardbox Talk > "Hours and Minutes Arithmetic"

Hours and Minutes Arithmetic

How do I put hours and minutes into a field in order to sum a selection of records?

Posted By Post

Alan Mason

22-Mar-2006 16:51

Can anyone tell me what I am missing (apart from a brain). I am running Cardbox 3, build 4223 and feel I must be missing something simple.

Mary Doyle

22-Mar-2006 21:03

Here is how I have done it. Could be done slightly more efficiently but this worked at the time I wrote it and I had too much else to do to go to the trouble of refining it.
I entered the hours and minutes with a colon e.g. 1:20. I must annotate the macro to explain more of how it works. Am just back from holidays so don't have time to do it now. If you can't figure it out let me know.


n = RecordCount

For i=1 to n
   x = Fields("time")
   a = InStr(x,":")
   b = a-1
   h = Left(x, b) 'hours

   y = Right(x,2) 'minutes
   w = 0 + w + h ' cumulative hours
   z = 0 + z + y ' cumulative minutes

If n>0 Then
  a = z\60 ' \ divides to give the integer result e.g. 7\2 = 3 i.e. the whole number
  b = z mod 60 'mod divides to give the remainder e.g. 7 mod 2 = 1, i.e. remainder
  w = 0 + w + a
  Fields("ct") = w & ":" & b ' This is a field I use to total the result - adapt as necessary
  End If


22-Mar-2006 21:03

You can count time with a macro.
Here is a very native macro. In field TY time is stored in this format m:ss or m.ss. No hours.
With some fantasie you can modify this to something beautiful. The macro language is powerful enoug to make what you want to make.


if ActiveRecord.userediting = true then
  msgbox "Record is not saved"
end if

For x = RecordPosition to Records.Count
   'check if there are enough positions - otherwise, skip!
   if len(Trim(Fields("TY"))) > 3 then
      minuut = Left(Trim(Fields("TY")), len(Trim(Fields("TY")))-3)
      seconde = Right(Trim(Fields("TY")), 2)
      tyd = TimeSerial(0, minuut, seconde)
      teltyd = timevalue(teltyd+tyd)
   end if

if len(second(teltyd)) = 1 then
     seconden="0" & second(teltyd)
   seconden = second(teltyd)
end if

telmsg = (hour(teltyd)*60) + minute(teltyd) & ":" & seconden
Msgbox "Total time " & telmsg & " (= " & teltyd & ")"

© 2010 Cardbox Software Limited   Home