|
-
Apr 10th, 2000, 12:55 AM
#1
Thread Starter
New Member

Hi
I got help from someone on ICQ that made (or modified) me a code that could take one time, and another one, and then find the time difference between those two.
The code wasn't perfect thou... In my program, one of the times is a time stamp (let's say 22:38:40), and the other time is the current time being constantly updated by a timer (let's say it's 22:38:47). It works fine up to 22:38:59, but when the current time passes to the next minute (22:38:47) the time difference, which has worked fine so far, starts counting on the minus side. 
If the time stamp shows 22:38:40 and the real time is 22:39:00 the time difference will now show 00:-1:-40. Then it will continue to count down. 22:39:05 will be 00:-1:-35 and so on. And when it counts down to 22:39:40, it finally goes back to the plus side again and the time difference shows 00:01:00. It counts correctly all in all, but it doesn't look correct some or most of the time.
Could somebody please help me with this? The code will be posted as a reply to this topic, so check it out if you want and send me a modified code.. Thanks 
-Joakim Stai
-
Apr 10th, 2000, 01:16 AM
#2
Thread Starter
New Member
The code
Here is the code.. Please modify and twist it as much you want, but send it to me when you think you got it 
First place a CommandButton, a Timer and 3 Labels on a Form.
Label1 is the time stamp, Label2 is the current time (always updated) and Label 3 is the time difference.
Then set the timer.. Timer1.Enabled = False, Timer1.Interval = "1000".
Now click the button and wait and see.
Private Sub Command1_Click()
Label1 = Time
Label2 = Time
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Label2 = Time
hur = Hour(Label2) - Hour(Label1)
If Len(hur) = 1 Then hur = "0" & hur
Min = Minute(Label2) - Minute(Label1)
If Len(Min) = 1 Then Min = "0" & Min
sec = Second(Label2) - Second(Label1)
If Len(sec) = 1 Then sec = "0" & sec
Label3 = hur & ":" & Min & ":" & sec
End Sub
-
Apr 10th, 2000, 03:23 AM
#3
Hyperactive Member
Hi, there.
Try this. It's for seconds,but you have to apply the same logic to hours and minutes.
Code:
If Second(Label1) > Second(Label2) Then
Label3 = hur & ":" & Min & ":" & -sec
If sec = 59 Then sec = "00"
Else
Label3 = hur & ":" & Min & ":" & sec
If sec = 59 Then sec = "00"
End If
May be there is a better way to do it.
Larisa
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|