Function TimeToSeconds Lparameter indata Return VAL(LEFT(indata,2))*3600 + VAL(SUBSTR(indata,4,2))*60 + VAL(RIGHT(indata,2)) Function SecondsToHour Lparameter indata Return PADL(INT(indata/3600), 6, "0") + ":" + PADL(INT((indata%3600)/60),2, "0")3. Save the file
Set library to MyLibto the init of your form. Or add it before
Do form xxx Read EventsPersonally I also include the line in my Startup.prg file, so I can always use the functions.
>USE curbilldata > >DO WHILE NOT EOF() > m.divi = curbilldata.divi > DO WHILE m.divi = curbilldata.divi AND NOT EOF() > SKIP > ENDDO > > > IF NOT EOF() > m.lnCurRec = RECNO() > INSERT BEFORE BLANK > SUM VAL(LEFT(m1_m,2))*3600 + ; > VAL(SUBSTR(m1_m,4,2))*60 + ; > VAL(RIGHT(m1_m,2)) TO lnSec for m.divi = curbilldata.divi >m.dae= PADL(INT(lnSec/3600), 6, "0") + ":" + ; > PADL(INT((lnSec%3600)/60),2, "0") > > > > GOTO m.lnCurRec > replace m1_m WITH m.dae > SKIP &&& i get error > ENDIF >ENDDO > >>thanks
>>SUM VAL(LEFT(m1_m,2))*3600 + ; >> VAL(SUBSTR(m1_m,4,2))*60 + ; >> VAL(RIGHT(m1_m,2)) TO lnSec >>m.dae= PADL(INT(lnSec/3600), 6, "0") + ":" + ; >> PADL(INT((lnSec%3600)/60),2, "0")>>However, I STRONGLY recommend that you add a TimeToSeconds function to your library:
>>Function TimeToSeconds >>Lparameter indata >>Return VAL(LEFT(indata,2))*3600 + VAL(SUBSTR(indata,4,2))*60 + VAL(RIGHT(indata,2))>>And a SecondsToHour function:
>>Function SecondsToHour >>Lparameter indata >>Return PADL(INT(indata/3600), 6, "0") + ":" + PADL(INT((indata%3600)/60),2, "0")>>This way your formula will be:
>>m.dae=SecondToHour( TimeToSeconds('34:20') + TimeToSeconds('36:40') + TimeToSeconds('71:10') + TimeToSeconds('66:10'))>>Remember, it's much more readable to create a library of functions, and use these functions, instead of using the complete formulas many places.
>>>>> SUM VAL(LEFT(m1_m,8))*3600 + ; >>>>> VAL(SUBSTR(m1_m,6,2))*30 + ; >>>>> VAL(RIGHT(m1_m,2)) TO lnSec >>>>> m.dae= PADL(INT(lnSec/3600), 6, "0") + ":" + ; >>>>> PADL(INT((lnSec%3600)/60),2, "0") >>>>>>>>>>thanks.