Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Second to hours and minutes

Posted on 2004-08-28
3
Medium Priority
?
254 Views
Last Modified: 2010-04-17
i am currently using this code to show time in hours and minutes from seconds. (ttime = seconds) Every 60 seconds it i make it refresh itself. It works great, the only problem that i see with it is that sometimes when its about to change from hole hours. This is what happens. It displays 02:00 then it displays (60s after) 01:00 then (60s after) 01:59. Another example would be 01:00 then 00:00 then 00:59. How can i fix this? Vb6

h = Int(Val(ttime) / 3600)
m = Int((Val(ttime) / 60) Mod 60)
If h < 10 Then
h = "0" & h
End If
If m < 10 Then
m = "0" & m
End If
0
Comment
Question by:DARKSAGES
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
DarkoLord earned 2000 total points
ID: 11922518
Hi, try this (it also converts to days):

            Dim seconds As Long
            Dim d As Long 'days
            Dim h As Long 'hours
            Dim m As Long 'minutes
            Dim s As Long 'seconds

            seconds = 86401 'one day, zero hours and mins and one sec

            If (seconds >= 86400) Then
                d = seconds \ 86400
                seconds = seconds Mod 86400
            End If

            If (seconds >= 3600) Then
                h = seconds \ 3600
                seconds = seconds Mod 3600
            End If

            If (seconds >= 60) Then
                m = seconds \ 60
                seconds = seconds Mod 60
            End If
            s = seconds

Darko
0
 

Author Comment

by:DARKSAGES
ID: 11922797
Thanx, for the quick answer. That was really easy but i have something due really soon and i cant think straight.
0
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11922823
You're welcome

Darko
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Screencast - Getting to Know the Pipeline

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question