I have been playing with trying to convert 'seconds' ( a six digit number) into hours;minutes;seconds.
I finally came up with the following code that will return the hh:mm:ss in the immediate window, but not in the application itself. It keeps sticking on 'MyHours = bigseconds \ 3600'
What am I missing?
Function converttime(bigseconds) As Variant
'Dim newtime As Variant
Dim MyHours As Variant
Dim myminutes As Variant
Dim myseconds As Variant
Dim bigseconds As Long
If bigseconds = "" Then
Debug.Print bigseconds
If IsError(bigseconds) = False Then
MyHours = bigseconds \ 3600
myminutes = (bigseconds - (MyHours * 3600)) \ 60
If Len(myminutes) < 2 Then myminutes = "0" & myminutes
myseconds = (bigseconds - (MyHours * 3600)) Mod 60
If Len(myseconds) < 2 Then myseconds = "0" & myseconds
Else
MyHours = 0
myminutes = 0
myseconds = 0
End If
If MyHours <> 0 Then
If Len(myminutes) < 2 Then myminutes = "0" & myminutes
converttime = MyHours & ":" & myminutes & ":" & myseconds
Else
converttime = myminutes & ":" & myseconds
End If
End Function
CoachPhil
I finally came up with the following code that will return the hh:mm:ss in the immediate window, but not in the application itself. It keeps sticking on 'MyHours = bigseconds \ 3600'
What am I missing?
Function converttime(bigseconds) As Variant
'Dim newtime As Variant
Dim MyHours As Variant
Dim myminutes As Variant
Dim myseconds As Variant
Dim bigseconds As Long
If bigseconds = "" Then
Debug.Print bigseconds
If IsError(bigseconds) = False Then
MyHours = bigseconds \ 3600
myminutes = (bigseconds - (MyHours * 3600)) \ 60
If Len(myminutes) < 2 Then myminutes = "0" & myminutes
myseconds = (bigseconds - (MyHours * 3600)) Mod 60
If Len(myseconds) < 2 Then myseconds = "0" & myseconds
Else
MyHours = 0
myminutes = 0
myseconds = 0
End If
If MyHours <> 0 Then
If Len(myminutes) < 2 Then myminutes = "0" & myminutes
converttime = MyHours & ":" & myminutes & ":" & myseconds
Else
converttime = myminutes & ":" & myseconds
End If
End Function
CoachPhil