Countdown & Timer...

skilche1

Registered User.
Local time
Today, 14:52
Joined
Apr 29, 2003
Messages
226
I am working on several databases and have one that need a countdown timer. Here is the scenario; I am creating a db to track samples that we put into a weatherometer (simulating exposed sun light over a period of time) with periodic sample checking. The countdown format I would like to see is dd/hh/mm in a forum.

I need this for two functions. 1st is to be able to countdown to the next light bulb change (every 1500 hours). 2nd is a timer that shows the current time samples have been exposed with the option to pause when we perform periodic sample checks, then resume which is also linked to the countdown timer as well (linking back to the countdown is critical so it doesn’t continue when the light is off). This also needs to be continued on computer start-up the next day without missing a second. I would to be able to input the start date for the countdown in a textbox in a form, stored in a table and shown in a form.
Is there anyone that can help me out with this?

Thanks

Steve
 
Simple Software Solutions

I would suggest you have a dedicated pc that is not switched off at the end of the day. This would just sit there monitoring the elapsed times.

You would have a form that has the options to allow for a pause in the timer by way of toggle buttons.

On the form timer event (set to 1000) = 1 second code it so it adds one second to the running time. Do you realy need to be so precise? As each timer interval reached zero it updates a field in a table with the running time.

To pause the clock on the toggle button you simply set the TimerInterval to 0
To resume set the TimerInterval to 1000 (1 second)

If you cannot run to a dedicated pc then when you close the database store the actual time you closed it to a field then when you restart the app get the system to calculate the difference between switch off time and switch on time and add this to the running time.


What happens if you perform a periodic check when the pc is down?

CodeMaster::cool:
 
OK, I think I follow. Once this db is complete, it will be located on a our company server to be accessed by local machines. So, I believe that answers your question. However, in the event of sever malfunction, this would interrupt the countdown and timer, which is something that cannot happen.

When the periodic checks are performed, it's during working hours. However, one cannot overlook computer crashes and unsuspected power outages. That is why I wouldlove to see this pick on the current day/time when its live.

As far as precision is concerned, minutes and seconds are not required, just so I am within the hour. This is a sensitive testing procedure that I believe is covered in the ASTM standards.

I apreciate your help DCrake.
Thanks :)
 
Simple Software Solutions

There is no reason why you cannot use the system date and time.
All you need to do is to create a starting point when you initiate the timer

then every minute get the app to examine the computer time

Then use the DateDiff() to calculate the difference in minutes

Code:
Mins = DateDiff("n",StartDateTime,Now())

Then use this function to calculate the actual interval in hours and mins


Code:
Function MinsToTime(Mins As Integer) As String
    MinsToTime = Mins \ 60 & " hour" & IIf(Mins \ 60 <> 1, "s ", " ") & Mins Mod 60 & " minute" & IIf(Mins Mod 60 <> 1, "s", "")
End Function

If you pause the timer at any point have a second field that holds the duration the pause lasted and deduct this from the mins before calling the MinsToTime Function

On your form you can then display the current duration


David
 
Thanks Dave. I will put it to use and will update.

Thanks again,

Steve
 
There is no reason why you cannot use the system date and time.
All you need to do is to create a starting point when you initiate the timer

then every minute get the app to examine the computer time

Then use the DateDiff() to calculate the difference in minutes

Code:
Mins = DateDiff("n",StartDateTime,Now())

Then use this function to calculate the actual interval in hours and mins


Code:
Function MinsToTime(Mins As Integer) As String
    MinsToTime = Mins \ 60 & " hour" & IIf(Mins \ 60 <> 1, "s ", " ") & Mins Mod 60 & " minute" & IIf(Mins Mod 60 <> 1, "s", "")
End Function

If you pause the timer at any point have a second field that holds the duration the pause lasted and deduct this from the mins before calling the MinsToTime Function

On your form you can then display the current duration


David

Dave,

I tried it and I cannot seemto put it all together. I am a novice at Access and know how to get around, not much of VBA, but learning. Would it be possible for you to walk me throuigh this. Hote to be a pain, but I tried.

Here is an image of wha ti trying to do:

A statred above, I am creating a database that requires us to change a light bulb after 1500 hours of use and this is something I ma looking for for my db. I am also looking for a means to pause the countdown timer when we perform peridoc sampling of the test samples. Note footnote 2 on image. Note: I had to type in the remaining time into the image to show what I need.

Another thing I am trying to figure out and seems harder than I imaged and I know it shouldn't be. I am trying to add additional (1500) hours the original date in which the bulb was changed. When I attempt the formula, I end up changing the year, not the month, day and hour. Note footnote 1 on image.

weatherometer.jpg


Thanks,

Steve
 
Last edited:
Simple Software Solutions

The second item you commented on is as follows

Next Bulb Change = DateAdd("h",1500,Date Switched On)

Code simplified for brevity.

What you have not mentioned, or I have not noticed it is; when you pause the timer do you want the paused time to be added to the original 1500hrs to ensure that the total length of time the bulb was lit is 1500hrs or does this not matter?

David
 
The second item you commented on is as follows

Next Bulb Change = DateAdd("h",1500,Date Switched On)

Code simplified for brevity.

What you have not mentioned, or I have not noticed it is; when you pause the timer do you want the paused time to be added to the original 1500hrs to ensure that the total length of time the bulb was lit is 1500hrs.

David

Yes, that is exactly what I am looking for. After thinking what I am trying to do, may I ask for assistance for another method to get the results I am trying to get? Would it be possible to manually enter the date (Date/Time) in a txtBox1 when the BULB was changed, then have a calculation add 1500 hours (life expectance of the light bulb) to the date/time entered into the txtBox1, then in another txtBox2, indicating the next date and the time of the next change as well as another txtBox3 informing the db user how many days/hour/minutes are left on bulb’s life. I prefer this method because I want to incorporate a “Pause/Resume” toggle switch, causing the txtBox2 to change to a new date/time and txtBox3 to change the amount of days/time remaining.

This feature is important because we do periodic sample evaluation every 409 hours, which requires time down time on the weatherometer. Not to mention down time between testing. In other words, if we do not sample another batch say 6 after the first batch is completed, I wouldn’t want the downtime to be calculated.


Thanks DC,

Steve
 
Last edited:
Simple Software Solutions

Steve,

You can do exactly as you suggested.

Think of it as a time line..

T = Date Started
N = Now()

A = N :Current Date/Time
B = N + 409 hours :next periodic check due
C = T + 1500 hours : life expectancy

D = A-B : Time remaining before next periodic check due
E = C-A : count down from 1500 hours
F= Down Time

If you are adding down time to make up 1500 then add F to C

-----A-----------------------------
T----------B---------------------C--(F)
|-----D----|
|----------------|--------E--------|


By drawing a time line you will points of interest along this line simply use the mathmatical logic to calculate the difference between the two points.
So every hour the duration the bulb has been lit will increasde by one and conversley the life expectancy should be reduced by one. Because we know that we normally do a periodic check at 409 hours we can first ask the question have I been lit for over 409 hours? if not how long will it be before I reach 409 hours. If I have passed 409 hours I can state the actual date/time that the check took place.

Follow my logic?

David
 
Steve,

You can do exactly as you suggested.

By drawing a time line you will points of interest along this line simply use the mathmatical logic to calculate the difference between the two points.
So every hour the duration the bulb has been lit will increasde by one and conversley the life expectancy should be reduced by one. Because we know that we normally do a periodic check at 409 hours we can first ask the question have I been lit for over 409 hours? if not how long will it be before I reach 409 hours. If I have passed 409 hours I can state the actual date/time that the check took place.

Follow my logic?

David

Dave,

Yes, I do follow your logic. The problem is... Although I do understand exactly what you're saying, I have no idea how to code it. At least, to this level. I just know the "very" basics....

Steve
 
Simple Software Solutions

The first thing you need on your form is a timer event.

Go to the properties of the form and scroll down to Timer Event and Timer Interval

On the timer Interval type in 60000 (1000 = 1 second) therefore 60000 = 1 minute.

Next on the code behind your timer event place code here.

Create the text boxes on the screen which contain the data you want to show.



Every time the timer interval reaches zero Acces will fire up the code behind your OnTimer event

Code:
Private Sub Form_Timer()
Dim IntMinsLifeLeft As Integer
Dim IntMinsNextTest As Integer

[COLOR="SeaGreen"]'This calulates the number of minutes between now and the date/time the bulb expectancy is. (Date switched on plus 1500hrs)[/COLOR]

IntMinsLifeLeft = DateDiff("n",Now(),ExpireDate)

[COLOR="seagreen"]'This line uses the function posted earlier to convert into hours and mins[/COLOR]
Me.TxtLifeRemaining = MinsToTime(IntMinsLifeLeft)

[COLOR="seagreen"]'Calculates when the next period test should be[/COLOR]
IntMinsNextTest = DateAdd("h",409,StartDate)


Me.TxtNextCheckDateTime = MinsToTime(IntMinsNextTest)

[COLOR="seagreen"]'The actual date and time the next period check should be: start time  plus 409 hours.[/COLOR]

Me.ActualPeriodCheckDateTime = Format(DateAdd("h",409,StartDate),"dd mm yyyy h:nn am/pm")

End Sub


Do you get the gist?

Not going to do everything for you or you will not learn anything. Cutting and pasting is like doing a crossword with the answers underneath.

David.
 
Not going to do everything for you or you will not learn anything. Cutting and pasting is like doing a crossword with the answers underneath.

David.

Thanks Dave. Having you actually create this was never my intention. You gave me a great start and appreciate your assistance. I never stop learning. :)

Thanks.

Steve
 
Simple Software Solutions

Steve,

Learing is one thing, climbing on the backs of Giants is another. By giving you the wherewithall to get you going was all you needed. Let me know how you get on. Don't forget when people help you out it is only curtious to up their reputation.
 
Steve,

Learing is one thing, climbing on the backs of Giants is another. By giving you the wherewithall to get you going was all you needed. Let me know how you get on. Don't forget when people help you out it is only curtious to up their reputation.

Understand Dave.

Have a great day and I will update my results later.

Thanks agian,

Steve
 

Users who are viewing this thread

Back
Top Bottom