INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Convert Seconds To A Format  (Read 1126 times)

KingSparta

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 20048
Convert Seconds To A Format
« on: January 08, 2005, 12:02:27 pm »

Since The SDK Does Not Allow For A File Name Frendly Format Due To The ":" This Sup Will Take Seconds And Convert It To, Days, Hours, Mins And Seconds. In A Standard Format Used By Many Program.

SecondsToText(Seconds) will return the info to Duration.Caption or what ever string you change it to

Function SecondsToText(Seconds) As String
    Dim bAddComma As Boolean
    Dim Result As String
    Dim sTemp As String
    '
    Dim days As Integer
    Dim hours As Integer
    Dim minutes As Integer
    If Seconds <= 0 Or Not IsNumeric(Seconds) Then
        SecondsToText = "0 seconds"
        Exit Function
    End If
    Seconds = Fix(Seconds)
    If Seconds >= 86400 Then
        days = Fix(Seconds / 86400)
    Else
        days = 0
    End If
    If Seconds - (days * 86400) >= 3600 Then
        hours = Fix((Seconds - (days * 86400)) / 3600)
    Else
        hours = 0
    End If
    If Seconds - (hours * 3600) - (days * 86400) >= 60 Then
        minutes = Fix((Seconds - (hours * 3600) - (days * 86400)) / 60)
    Else
        minutes = 0
    End If
    Seconds = Seconds - (minutes * 60) - (hours * 3600) - (days * 86400)
    If Seconds > 0 Then
        If Seconds < 10 Then
            Result = "0" & Seconds & "s"
        Else
            Result = Seconds & "s"
        End If
    Else
        Result = "00s"
    End If
    If minutes > 0 Then
        If minutes < 10 Then
            sTemp = "0" & minutes & "m"
        Else
            sTemp = minutes & "m"
        End If
        Result = sTemp & Result
    End If
    If hours > 0 Then
        If hours < 10 Then
            sTemp = "0" & hours & "h"
        Else
            sTemp = hours & "h"
        End If
        Result = sTemp & Result
    End If
    If days > 0 Then
        If days < 10 Then
            sTemp = "0" & days & "d"
        Else
            sTemp = days & "d"
        End If
        Result = sTemp & Result
    End If
    Duration.Caption = "(" & Result & ")"
End Function
Logged
Retired Military, Airborne, Air Assault, And Flight Wings.
Model Trains, Internet, Ham Radio
https://MyAAGrapevines.com
Fayetteville, NC, USA
Pages: [1]   Go Up