Article ID: 115055
Article Last Modified on 12/3/2003
* TIMECALC.PRG
PARAMETERS bt,et,op
hr1=VAL(LEFT(bt,2))
hr2=VAL(LEFT(et,2))
mn1=VAL(SUBSTR(bt,4,2))
mn2=VAL(SUBSTR(et,4,2))
sc1=VAL(RIGHT(bt,2))
sc2=VAL(RIGHT(et,2))
tot1=(hr1*3600)+(mn1*60)+sc1
tot2=(hr2*3600)+(mn2*60)+sc2
IF op=1
tt=tot1+tot2
ELSE
tt=tot2-tot1
ENDIF
thr=ALLTRIM(STR(INT(tt/3600)))
tmn=ALLTRIM(STR(INT((tt%3600)/60)))
tsc=ALLTRIM(STR((tt%3600)%60))
tdc=RIGHT(STR(INT((VAL(tmn)/60)*10)/10,5,1),1)
RETURN chr(13)+' '+ ;
thr+' hour'+iif(val(thr)<>1,'s','')+', '+ ;
tmn+' minute'+iif(val(tmn)<>1,'s','')+', '+ ;
tsc+' second'+iif(val(tsc)<>1,'s','')+'.' + ;
chr(13)+chr(13)+ ' Decimal equivalent: '+ ;
thr+'.'+tdc+' hour'+iif(val(tdc)<>1,'s','')+'.'+chr(13)
*-> FOR MS-DOS and Macintosh
? timecalc('00.05.15','01.25.00',1)
? timecalc('00.05.15','01.25.00',2)
*-> FOR WINDOWS 2.5
SET TEXTMERGE ON
\<<timecalc('00.05.15','01.25.00',1)>>
\<<timecalc('00.05.15','01.25.00',2)>>
SET TEXTMERGE OFF
*-> FOR 2.5a MS-DOS or WINDOWS
WAIT WIND timecalc('00.05.15','01.25.00',1) NOWAIT
WAIT WIND timecalc('00.05.15','01.25.00',2) NOWAIT
**** R E S U L T S ******************************
* (1=ADDITION) returns:
*
* 1 hour, 30 minutes, 15 seconds.
*
* Decimal equivalent: 1.5 hours.
*
* (2=SUBTRACTION) returns:
*
* 1 hour, 19 minutes, 45 seconds.
*
* Decimal equivalent: 1.3 hours.
*
* NOTE: While a period is used in this example as a separator
* character for hr.mn.sc, any other character may be used.
The following program demonstrates a FoxPro for Windows-specific
implementation of the TimeCalc() function, which tracks the time since the
current FoxPro session began. The timer can optionally be reset. This
example uses a program file called by the CONFIG.FPW file when FoxPro is
started to initialize the variables and set keytraps for displaying and
resetting the timer.
*** T I M E T R A K . P R G
*
PUBLIC btime
ON KEY LABEL F4 btime=TIME()
ON KEY LABEL F5 WAIT WINDOW TimeCalc( btime, TIME(), 2 ) NOWAIT
KEYBOARD "{F4}"
* end of program
To have the program load automatically when FoxPro starts, modify the
CONFIG.FPW file to include the following line:
COMMAND=DO timetrakTo use the timer, press F5 to display how long FoxPro has been running. You can display the elapsed time at any time during the session by pressing F5.
Additional query words: VFoxWin FoxMac FoxDos FoxWin timing stopwatch lap
Keywords: kbcode KB115055