P°evod sekund na hodiny, minuty a sekundy

Funkce:

Public Function TimeString(Seconds As Long, Optional Verbose As Boolean = False) As String

   
'je-li verbose = false, pak funkce vracφ
   'n∞co takovΘho - 02:22.08
   'je-li true, vracφ
   '2 hodiny, 22 minut a 8 sekund


   Dim lHrs As Long
   Dim lMinutes As Long
   Dim lSeconds As Long

   lSeconds = Seconds

   lHrs = Int(lSeconds / 3600)
   lMinutes = (Int(lSeconds / 60)) - (lHrs * 60)
   lSeconds = Int(lSeconds Mod 60)

   Dim sAns As String

   If lSeconds = 60 Then
   
   lMinutes = lMinutes + 1
      lSeconds = 0
   End If

   If lMinutes = 60 Then
      lMinutes = 0
      lHrs = lHrs + 1
   End If

   sAns = Format(CStr(lHrs), "#####0") & ":" & _
   Format(CStr(lMinutes), "00") & "." & _
   Format(CStr(lSeconds), "00")

   If Verbose Then sAns = TimeStringtoCZ(sAns)
   TimeString = sAns

End Function

Private Function TimeStringtoCZ(sTimeString As String) As String

   Dim sAns As String
   Dim sHour, sMin As String, sSec As String
   Dim iTemp As Integer, sTemp As String
   Dim iPos As Integer

   
iPos = InStr(sTimeString, ":") - 1

   sHour = Left$(sTimeString, iPos)
   If CLng(sHour) <> 0 Then
      sAns = CLng(sHour) & " hodina"
      If CLng(sHour) > 1 Then sAns = "hodiny"
      sAns = sAns & ", "
   End If

   sMin = Mid$(sTimeString, iPos + 2, 2)

   iTemp = sMin

   If sMin = "00" Then
      sAns = IIf(Len(sAns), sAns & "0 minut a ", "")
   Else
      sTemp = IIf(iTemp = 1, " minuta", " minut")
      sTemp = IIf(Len(sAns), sTemp & ", a ", sTemp & " a ")
      sAns = sAns & Format$(iTemp, "##") & sTemp
   End If

   iTemp = Val(Right$(sTimeString, 2))
   sSec = Format$(iTemp, "#0")
   sAns = sAns & sSec & " sekund"

   TimeStringtoCZ = sAns

End Function

Zp∞t

Autor: The Bozena