This program will be for adding times in minutes and seconds and presenting the output in an attractive mm:ss format. It is part of a larger work in progress intended for adding segment times of TV programs in minutes and seconds (all segment times are presumed to be under one hour). The finished program will convert segment times to seconds, add the number of seconds and display the result in mm:ss format.
You would think this could be done in Excel, but Excel gives inaccurate results when adding segment times. I have tried different time formats in Excel but no joy.
Suggestions welcome.
Code:
Global time$,seconds
Procedure ToSeconds(time$)
seconds=Val(StringField(time$,1,":")) *60 ;CONVERT MINUTES TO SECONDS
seconds+Val(StringField(time$,2,":"))
;Debug seconds
EndProcedure
Procedure FormatTimestr(seconds)
;mins = Val(StringField(time$,1,":"))
mins = Int(seconds / 60)
secs = seconds - (mins * 60)
If secs < 10: sec$ = "0" + Str(secs) ;PAD WITH LEADING 0
Else
sec$ = Str(secs)
EndIf
If mins > 0 ;DROP LEADING 0
Debug Str(mins) + ":" + sec$
Else
Debug ":" + sec$
EndIf
EndProcedure
;ToSeconds ("1:30")
FormatTimestr(121)