|
-
Apr 7th, 2000, 02:19 PM
#1
Thread Starter
Addicted Member
Hi
I dont really know how to explain this so I hope someone can understand what I am getting at.
I have encountered a little bit of problem I don't have a clue how to fix. I am using a code serge gave someone on another topic for subtracting 1 time from another. I am using this code, as a timer to time certain events, and functions. I have it timing the current session of a event. The total amount of time spent on this event during that day, and the time for the month. The session code works fine, because I only have to time that session and can start from scratch each time. But the problem is the day and the month times. Because I need to add on the previous times as well. To explain it properly I am going to have to show the code First off the code serge posted was this:
Dim datStart As Date
Dim datFinish As Date
Dim strMsg As String
datStart = Now
'Do your processes here
datFinish = Now - datStart
strMsg = "The whole process took" & vbCrLf
strMsg = strMsg & "Hours: " & Hour(datFinish) & vbCrLf
strMsg = strMsg & "Minutes: " & Minute(datFinish) & vbCrLf
strMsg = strMsg & "Seconds: " & Second(datFinish)
MsgBox strMsg
and I adjusted it so it was something like this
'in the general declarations
Dim SessionStart As Date
Dim SessionFinish As Date
Dim DayStart As Date
Dim DayFinish As Date
'I the session, the day and the month all have four labels each
'1 for the time to be shown, and the others hold either the hours, the
'minutes or the seconds
Private Sub SessionCalc_Timer()
SessionFinish = Now - SessionStart
SessionHour.Caption = Hour(SessionFinish)
SessionMinute.Caption = Minute(SessionFinish)
SessionSecond.Caption = Second(SessionFinish)
End Sub
Private Sub LabelCalc_Timer()
'I wanted the label displaying it 2 have 2 digits under each field, but
'when the minutes hour or seconds were below 10 they were only one
'digit so this deals with this for the session..
If SessionHour.Caption <= 9 Then
SessionHour.Caption = "0" + SessionHour.Caption
End If
If SessionMinute.Caption <= 9 Then
SessionMinute.Caption = "0" + SessionMinute.Caption
End If
If SessionSecond.Caption <= 9 Then
SessionSecond.Caption = "0" + SessionSecond.Caption
End If
SessionTime.Caption = SessionHour.Caption + ":" + SessionMinute.Caption + ":" + SessionSecond.Caption
End Sub
Private Sub DayCalc_Timer()
DayFinish = Now - DayStart
DayHour.Caption = Hour(DayFinish)
DayMinute.Caption = Minute(DayFinish)
DaySecond.Caption = Second(DayFinish)
End Sub
If DayHour.Caption <= 9 Then
DayHour.Caption = "0" + DayHour.Caption
End If
If DayMinute.Caption <= 9 Then
DayMinute.Caption = "0" + DayMinute.Caption
End If
If DaySecond.Caption <= 9 Then
DaySecond.Caption = "0" + DaySecond.Caption
End If
DayTime.Caption = DayHour.Caption + ":" + DayMinute.Caption + ":" + DaySecond.Caption
End Sub
I also have 3 more captions for the month and day to hold the time that has been used so far for that event that has been saved which need to be added to the days, and months time ect, but if well the problem is that if I had the time it has been timing, each time the seconds or minutes goes up it will change to the amount of time since the time has started counting again. I can keep adding it on after each time the labels changed, but say the seconds saved from total time that day were 40 seconds, and then the seconds it was counting were up to 40 seconds the seconds would say 80 seconds. and if I use an if statement to tell it once it has reach 59 to make it 0 and add 1 on to minutes caption well it slows down the timer over all making it less accurate. There is probably a really simple way to get around this, but I can't think of it at the moment.
can someone please help?
-
Apr 7th, 2000, 03:21 PM
#2
Lively Member
this should work for the rest of you progam also
Code:
'in form_load
sessionstart = now
'in timer
sessionHour.Caption = Format(now - sessionstart, "hh")
sessionMinute.Caption = Format(Now - SessionStart, "nn")
sessionSecond.Caption = Format(Now - SessionStart, "ss")
sessiontime.Caption = Format(Now - SessionStart, "hh:mm:ss")
notice the hh,nn,ss in the format causes the display of 01,02,03,etc
dates are sim. to times, just diff args in the " " part.
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
hope this helps you...
NOTE: this code may cause problems on the time change at midnight.
[Edited by _bman_ on 04-08-2000 at 04:24 AM]
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
|