473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

timer function

I'm running a timer function that counts down from set time frames. It has
an odd tendency to drop 2 seconds at the beginning but then work fine the
rest of the way. Can anyone suggest what could be happening here?
Jul 23 '05 #1
2 1125
Darren Showers wrote on 09 nov 2004 in
microsoft.public.scripting.jscript:
I'm running a timer function that counts down from set time frames.
It has an odd tendency to drop 2 seconds at the beginning but then
work fine the rest of the way. Can anyone suggest what could be
happening here?


What is happening here is that you don't show us the code.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #2
Thank you for the unnecessary candor. Here is the code:

function startTimer() {
running = true;
var now = new Date();
start =now.getTime();
var seconds = getSec();
var setTime = 1000 * seconds;
endTime = start + setTime;
showCountDown()
}

function getSec() {
var r = document.frm.radio1;
for (var i=0; i<r.length; i++) {
if (!r[i].checked) continue;
else return r[i].value;
}
return null;
}

function showCountDown() {
var present = new Date();
moment = present.getTime();
if (endTime - moment<= 0) {
stopTimer();
displayTimer.innerHTML = "TIME'S UP!";
showTimeOver();
} else {
var lapse = new Date(moment - start);
var minLapse = lapse.getMinutes();
var secLapse = lapse.getSeconds() + 1;
var timeLapse = minLapse;
timeLapse += ((secLapse < 10) ? ":0" : ":") + secLapse;
document.frm.timeLapse.value = timeLapse;
var delta = new Date(endTime - moment);
var theMin = delta.getMinutes();
var theSec = delta.getSeconds();
theTime = theMin;
theTime += ((theSec < 10) ? ":0" : ":") + theSec;
document.frm.timerDisplay.value = theTime;
displayTimer.innerHTML = theTime;

if (running) {
timerID = setTimeout("showCountDown()",1000)
}
}
}

function stopTimer() {
displayTimer.innerHTML = theTime + " TIMER STOPPED";
clearTimeout(timerID);
running = false;
}
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.29...
Darren Showers wrote on 09 nov 2004 in
microsoft.public.scripting.jscript:
I'm running a timer function that counts down from set time frames.
It has an odd tendency to drop 2 seconds at the beginning but then
work fine the rest of the way. Can anyone suggest what could be
happening here?


What is happening here is that you don't show us the code.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Christine | last post by:
I've implemented a countdown timer for a tutorial web page that should give the user 45 minutes to complete the test, only to find that the timer is slowly 'losing' time. On average, it actually...
7
by: J. Hill | last post by:
I have a Windows Service with a timer but the .Tick event is not being fired/called. Don't know what code to include...I enabled and started the timer...I have the exact same code in a Windows...
6
by: Antti Laakso | last post by:
Hi i have function like above Public Sub halytystutkinta() Dim ds As New DataSet ds = dl2.HaeHalytys() Dim onkohal As Int16 onkohal = ds.Tables(0).Rows(0).Item("onkohalytys") halid =...
7
by: Noozer | last post by:
I have a timer on a form. It isn't firing at all. I know that the timer is enabled, and that the interval is low (4000, which should be 4 seconds). To ensure the timer wasn't being inadvertantly...
1
by: jmgro | last post by:
I have spent way too much time trying to solve the following problem: I have a datalist with a timer in the footer template. It works wonderfully except when the user pages back, then forward,...
10
by: Ryan | last post by:
I'm creating a website that monitors the status of servers using My.Computer.Network.Ping. I'm looking for a way to fire off my Ping() function every second or so. I see a Timer control...
4
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this...
4
by: jwriteclub | last post by:
Hello all, I have a quick question about timers in C#. I have a System.Windows.Forms.Timer timer (the kind you "drag" out of the toolbox. It looks something like this: public class...
7
by: ssecorp | last post by:
I am not clear about the results here. from timeit import Timer import Decorators def fib(n): a, b = 1, 0 while n: a, b, n = b, a+b, n-1
7
by: genesistr | last post by:
Hi, I have timer class and some classes use timer. but when i come back from timer with callback function, i can see this. properties. function Timer(dName, dCallback){ this.timer = null;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.