Ken:

Thanks.  I came up with these on my own.  Good enough for now.

:)

Jon

function timeToStr pTime  -- mm:ss.hh
 local m, s
 divide pTime by the timeScale of player "myPlayer"
 put pTime div 60 into m
 put pTime mod 60 into pTime
 put format("%2.0f:%2.2f", m, pTime) into pTime
return pTime end timeToStr

function StrToTime pTime  -- assumes same format as TimeToStr
 local mStr, sStr
 put char 1 to 2 of pTime into mStr
 put char 4 to 8 of pTime into sStr
 return ((mStr * 60) + sStr) * the timeScale of player "myPlayer"
end StrToTime





Ken Ray wrote:

Are there any simple ways to take times (like Player currentPositions or
Durations) and format them for the user so that they look like
"h:mm:ss.hh"?  I looked in the help for Format, but no joy.

You can use my handy-dandy 'stsConvertTime' function (watch for line wraps);
since I think the currentPosition/durations are in milliseconds, you can do
this:

on mouseUp
 put the duration of player 1 into tDur
 put stsConvertTime(tDur,"MS","HH:MM:SS.MS") into tResult
 answer tResult
end mouseUp

function stsConvertTime pValue,pInFormat,pOutFormat
 -- First, convert incoming value to milliseconds
 if isNumber(pValue) is false then
   return "Error: Incoming value is not a real number."
   exit stsConvertTime
 end if
if pInFormat = "" then put "MS" into pInFormat
 if pOutFormat = "" then put "HH:MM:SS.MS" into pOutFormat
switch pInFormat
 case "H"
   put (pValue*60*60*1000) into pMS
   break
 case "M"
   put (pValue*60*1000) into pMS
   break
 case "S"
   put (pValue*1000) into pMS
   break
 case "T"
   put (pValue/60)*1000 into pMS
   break
 case "MS"
   put pValue into pMS
   break
 end switch
 put 0 into tSecs
 put 0 into tMins
 put 0 into tHrs
 put pMS div 1000 into tSecs
 put pMS mod 1000 into tMS
 put tMS into tVal
 if tSecs <> 0 then
   put tSecs div 60 into tMins
   put tSecs mod 60 into tSecs
   if tMins <> 0 then
     put tMins div 60 into tHrs
     put tMins mod 60 into tMins
   end if
 end if
 -- No format return value
 if "MS" is in pOutFormat then replace "MS" with tMS in pOutFormat
 if "HH" is in pOutFormat then replace "HH" with _PadZero(tHrs) in
pOutFormat
 if "H" is in pOutFormat then replace "H" with tHrs in pOutFormat
 if "MM" is in pOutFormat then replace "MM" with _PadZero(tMins) in
pOutFormat
 if "M" is in pOutFormat then replace "M" with tMins in pOutFormat
 if "MM" is in pOutFormat then replace "MM" with _PadZero(tMins) in
pOutFormat
 if "M" is in pOutFormat then replace "M" with tMins in pOutFormat
 if "SS" is in pOutFormat then replace "SS" with _PadZero(tSecs) in
pOutFormat
 if "S" is in pOutFormat then replace "S" with tSecs in pOutFormat
 return pOutFormat
end stsConvertTime

function _PadZero pVal
 if pVal < 10 then return "0" & pVal
 else return pVal
end _PadZero
Have fun!


Ken Ray
Sons of Thunder Software
Email: [EMAIL PROTECTED]
Web Site: http://www.sonsothunder.com/



_______________________________________________
use-revolution mailing list
[email protected]
http://lists.runrev.com/mailman/listinfo/use-revolution


_______________________________________________
use-revolution mailing list
[email protected]
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to