Hi there,
How do i convert a number which is in seconds (eg 310 seconds) to 5 minutes 10 seconds?
Do i use the mod function (which i cant seem to be able to use in the pocket pc development.,.)
Printable View
Hi there,
How do i convert a number which is in seconds (eg 310 seconds) to 5 minutes 10 seconds?
Do i use the mod function (which i cant seem to be able to use in the pocket pc development.,.)
here is one i used before:
VB Code:
Public Function formatLength(ByVal howManySeconds As Object) As Object Dim mySeconds As Object Dim myHours As Object Dim myMinutes As Object On Error GoTo errCheck '//just incase of an error ' //duration ' mySeconds = howManySeconds 'if mySeconds is greater or equal to 3,600 seconds If mySeconds >= 3600 Then 'get hours which is equal to seconds divided by 3600 myHours = mySeconds / 3600 'set the seconds to the numbers after the decimal sign 'thats what mod does mySeconds = mySeconds Mod 3600 Else 'if not greater than 3600, just set it to 0 myHours = 0 End If If mySeconds >= 60 Then 'greater than or equal to 60 'set the minutes equal to the value of (seconds divided by 60). 'and get the remaining numbers after the decimal 'which will be the seconds 'using the mod sign myMinutes = mySeconds \ 60 mySeconds = mySeconds Mod 60 Else 'if not set to 0 myMinutes = 0 End If 'return formatLength = Format$(myHours, "00:") & Format$(myMinutes, "00:") & Format$(mySeconds, "00") Exit Function errCheck: formatLength = "" End Function
If you can't use Mod function in PPC development environ, wouldn't the following work:
Obviously you could add one more If/Then switch to account for hours if needed.VB Code:
Public Function ConvertRawSeconds(RawSeconds As Int) As String Dim RemainingSecs As Integer Dim Minutes As Integer Dim Seconds As Integer RemainingSecs = RawSeconds Minutes = 0 Seconds = 0 Do While RemainingSecs > 0 If RemainingSecs > 59 Then Minutes = Minutes + 1 RemainingSecs = RemainingSecs - 60 Else Seconds = RemainingSecs RemainingSecs = 0 End If Loop ' And borrowing/adapting syntax from Strider's previous posting ConvertRawSeconds = Format$(Minutes, "00:") & Format$(Seconds, "00") End Function
Found it !!
Quote:
Originally Posted by wossname
That was certainly more elegant than my suggestion.
Heee...i know....
Thank goodness i checked the forums again...
It was wossname who posted it.. i am just putting it here so pple knows it works on the CF.