Page 1 of 1

Countdown Timer

PostPosted: Fri Dec 05, 2014 12:41 pm
by stevec
I am trying to come up with a simple countdown time that displays the remaining time.

For example. Starting at 5 minutes and counting down to zero.

Is there any examples out there of the code?

Re: Countdown Timer

PostPosted: Fri Dec 05, 2014 1:03 pm
by dec
Hello stevec,

If you like, can take a look at my npHour plugin, which allow the "clocks" to be customized and act like countdown timers and provide the appropiate event/subroutine when the countdown is reached. Don't forget the "Countdown.pub" publication sample included by this plugin. ;)

Image

Re: Countdown Timer

PostPosted: Fri Dec 05, 2014 1:08 pm
by stevec
I built a countdown timer years ago and can't find the code to it. :cry: :cry: :cry: :cry:

Re: Countdown Timer

PostPosted: Fri Dec 05, 2014 1:10 pm
by dec
Hello,

stevec wrote:I built a countdown timer years ago and can't find the code to it. :cry: :cry: :cry: :cry:


Don't worry, probably other mate can help you! Start here for example!

Re: Countdown Timer

PostPosted: Fri Dec 05, 2014 2:54 pm
by stevec
Thanks DEC.

Re: Countdown Timer

PostPosted: Fri Dec 05, 2014 3:02 pm
by dec
Hello,

stevec wrote:Thanks DEC.


You're welcome stevec!

Re: Countdown Timer

PostPosted: Fri Dec 05, 2014 3:40 pm
by stevec
I looked on your site and didn't see how to register the npHour. Almost done for the day will check later. Thanks

Re: Countdown Timer

PostPosted: Fri Dec 05, 2014 3:59 pm
by dec
Hello,

stevec wrote:I looked on your site and didn't see how to register the npHour. Almost done for the day will check later. Thanks


First of all, try the plugin without time limit to be sure you found useful for your project. After that, without worries, visit the NeoPlugins Store and choose the plugin(s) you want to register. And, if you have any question, do not hesitate to contact me, for example, using this contact form, or just send me a PM on this forum, or write me an email, or post here or in any other post any question you have stevec.

Thanks for your interest! ;)

Re: Countdown Timer

PostPosted: Sat Dec 06, 2014 7:47 pm
by fkapnist
Here is a simple JavaScript countdown you can put into a NeoBook WebBrowser object

Code: Select all
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>JavaScript 30 Seconds Countdown</title>
    <script language="javascript">
    var max_time = 30;
    var cinterval;
     
    function countdown_timer(){
    // decrease timer
    max_time--;
    document.getElementById('countdown').innerHTML = max_time;
    if(max_time == 0){
    clearInterval(cinterval);
    }
    }
    // 1,000 means 1 second.
    cinterval = setInterval('countdown_timer()', 1000);
    </script>
    </head>
    <body>
    <p>Download will start in <span id="countdown">30</span> seconds.</p>
    </body>
    </html>



Here is another JScript countdown timer that sets off a function (it sends you to the Neosoft home page). It can also trigger a NeoBook Action...

Code: Select all
<HEAD>
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var start=new Date();
   start=Date.parse(start)/1000;
   var counts=30;
   function CountDown(){
      var now=new Date();
      now=Date.parse(now)/1000;
      var x=parseInt(counts-(now-start),10);
      if(document.form1){document.form1.clock.value = x;}
      if(x>0){
         timerID=setTimeout("CountDown()", 30)
      }else{
         location.href="http://www.neosoftware.com/"
      }
   }
//  End -->
</script>
<SCRIPT LANGUAGE="JavaScript">
<!--
window.setTimeout('CountDown()',30);
-->
</script>

</HEAD>

<BODY>

</center>
<FORM NAME="form1">
You are being redirected to the NeoSoft Corp. Page in <INPUT TYPE="text" NAME="clock" SIZE="2" VALUE="10"> seconds.
</FORM>
</center>



Note:

If you copy the code directly from the Neobook forum post and pasted it into a HTML editor it has the wrong character set and it will look something like this:

& lt ;FORM NAME= & quot; form1 " ;& gt ;< br>
You are being redirected to the NeoSoft Corp. Page in & lt ; INPUT
TYPE =& quot;text & quot; NAME="clock" SIZE=& quot ;2& quot;
VALUE = & quot ;10"> ; seconds.<br
& lt; FORM & gt;


It will not execute as HTML. You must first paste it into Notepad (which automatically converts it to ANSI) then copy it out of notepad and into your HTML editor. It will look like this and it will work:


FORM NAME="form1">
You are being redirected to the NeoSoft Corp. Page in <INPUT TYPE="text" NAME="clock" SIZE="2" VALUE="10"> seconds.
</FORM


Below I have a link to a sample NeoBook PUB which demonstrated the countdown scripts.

http://www.verticalbrowser.com/zips/countdowndemo.zip

:arrow:

Re: Countdown Timer

PostPosted: Tue Dec 09, 2014 7:43 am
by stevec
Thanks for all the input.

Here is what I was able to do. This code was not mine, I did alter it.

******** Button properties***************

Math "[M1]*60" "0" "[T1]"
SetVar "[thisCount]" "[T1]"
GoSub "DisplayCountDown"
TimerStart "Timer1" "1000"

**********************Subroutine*************

:DisplayCountDown
Math "trunc([thisCount]/60)" "0" "[thisMinute]"
Math "[thisCount]-(60*[thisMinute])" "0" "[thisSecond]"
.my change below
If "[ThisCount2]" ">" "120"
SetObjectFont "TextEntry1" "Lime" "Kingthings Christmas 2" "150" "Normal" "ANSI_CHARSET"
SetObjectFont "TextEntry2" "Lime" "Kingthings Christmas 2" "150" "Normal" "ANSI_CHARSET"
Else
If "[ThisCount2]" "<" "121"
SetObjectFont "TextEntry1" "255,86,4" "Kingthings Christmas 2" "150" "Normal" "ANSI_CHARSET"
SetObjectFont "TextEntry2" "255,86,4" "Kingthings Christmas 2" "150" "Normal" "ANSI_CHARSET"
GotoLine "13"
If "[ThisCount2]" "<" "61"
SetObjectFont "TextEntry1" "Red" "Kingthings Christmas 2" "150" "Normal" "ANSI_CHARSET"
SetObjectFont "TextEntry2" "Red" "Kingthings Christmas 2" "150" "Normal" "ANSI_CHARSET"
Return

************************Timer Properties***********************
Math "[thisCount]-1" "0" "[thisCount]"
Math "([thisMinute]*60)+[thisSecond]" "0" "[ThisCount2]"
GoSub "DisplayCountDown"
If "[thisCount]" "=" "0"
TimerStop "Timer1"
EndIf

*******************************************************************

many thanks again. :D :D :D

Re: Countdown Timer

PostPosted: Tue Dec 09, 2014 11:21 am
by MiNeoBook
Estoy atrasado???
ButtonCode
~~~~~~~~~~~~
setvar "[nHours]" "3"
setvar "[nMinutes]" "2"
setvar "[nSeconds]" "1"
math "[nHours]*3600+[nMinutes]*60+[nSeconds]" "" "[HMS]"
timerstart "HMS" "1000"
---------------------------------
TimerCode
~~~~~~~~~
math "[HMS]-1" "" "[HMS]"
math "trunc([HMS]/3600)" "" "[vHr]"
math "trunc(([HMS]-([vHr]*3600))/60)" "" "[vMi]"
math "([HMS]-([vMi]*60)-([vHr]*3600))/100" "2" "[vSc]"
math "[vHr]/100" "2" "[vHr]"
math "[vMi]/100" "2" "[vMi]"
substr "[vHr]" "3" "2" "[hh]"
substr "[vMi]" "3" "2" "[mm]"
substr "[vSc]" "3" "2" "[ss]"
if "[HMS]" "=" "0"
timerstop "HMS"
alertbox "ALERT" "READY"
endif

Re: Countdown Timer

PostPosted: Tue Dec 09, 2014 5:36 pm
by stevec
cool.
That is what is so amazing, is that there are multiple ways of doing things.
I had a grasp on 'subroutines' a while ago, but since I don't use it often enough, I lose it.

many thanks;