Count up/down display of time in HH:MM:SS
If your VisualNEO Win application needs to display a count up (or down) of time elapsed (or remaining) … in hours, minutes and seconds … formated as HH:MM:SS … the idea/subroutine described below will help you to do this.
First, create a Timer object called tc … configure it so …
- Start: is set to Wait for “TimerStart” action
- Variable: (to store elapsed time) is set to [tcElapsed]
… and its Timer Interval section contains …
... forced stop ?
If "[tcEndIt]" "=" "True"
TimerStop "tc"
If "[tcDoneRoutine]" "<>" ""
GoSub "[tcDoneRoutine]"
EndIf
Return
EndIf
... counting up or down ?
If "[tcStart]" "<" "[tcStop]"
TimerStop "tc"
If "[tcDoneRoutine]" "" ""
GoSub "[tcDoneRoutine]"
EndIf
Return
EndIf
Else
... [tcStop] exceeded ?
Math "trunc([tcElapsed]/1000)" "0" "[tcElapsedSeconds]"
Math "[tcStart]-[tcElapsedSeconds]" "0" "[tcNow]"
If "[tcNow]" "<" "[tcStop]"
TimerStop "tc"
If "[tcDoneRoutine]" "" ""
GoSub "[tcDoneRoutine]"
EndIf
Return
EndIf
EndIf
... format [tcNow]
Math "trunc([tcNow]/60)" "0" "[tcMM1]"
...
Math "[tcNow]-([tcMM1]*60)" "0" "[tcSS1]"
If "[tcSS1]" "<" "10"
SetVar "[tcSS]" "!0[tcSS1]"
Else
SetVar "[tcSS]" "[tcSS1]"
EndIf
...
Math "trunc([tcMM1]/60)" "0" "[tcHH]"
Math "[tcMM1]-([tcHH]*60)" "0" "[tcMM1]"
If "[tcMM1]" "<" "10"
SetVar "[tcMM]" "!0[tcMM1]"
Else
SetVar "[tcMM]" "[tcMM1]"
EndIf
...
Return
Case 1: Count Up
Insert this set of commands where you want the counter to be initiated …
... prefix text ; leave blank if not required
SetVar "[tcPrefix]" "Elapsed Time:"
... suffix text ; leave blank if not required
SetVar "[tcSuffix]" ""
...
... starting value (normally 0)
SetVar "[tcStart]" "5"
... refresh rate (number of seconds between updates)
SetVar "[tcRefresh]" "2"
... ending value (stop count when this value is reached)
SetVar "[tcStop]" "72000"
... variable to force termination before [tcStop] is reached
SetVar "[tcEndIt]" "False"
... subroutine to be called when display is stopped
... leave blank if not required
SetVar "[tcDoneRoutine]" "gkAllDone"
...
... now start the display
TimerStart "tc" "1000*[tcRefresh]"
In this case, the count up will begin at 0:00:05 … refresh every 2 seconds … and if not forced earlier, stop at 2:00:00 … and will trigger an external subroutine called gkAllDone when terminated.
If your applications need to invoke this facility frequently, you could create a VisualNEO function like …
Call "gkTC" "Elapsed Time:" "" "5" "2" "99000" "False" "gkAllDone"
And here is the code for the (optional) gkAllDone subroutine that you would place in the SubRoutines section of your App …
:gkAllDone
AlertBox "All Done" "[tcPrefix] [tcHH]:[tcMM]:[tcSS] [tcSuffix]"
Return
That is all.
If your application requires that the display count be prematurely terminated, all you need is a command like …
SetVar "[tcEndIt]" "True"
Case 2: Count Down
Insert this set of commands where you want the counter to be initiated …
... prefix text ; leave blank if not required
SetVar "[tcPrefix]" "Counting Down:"
... suffix text ; leave blank if not required
SetVar "[tcSuffix]" "remaing ..."
...
... starting value (1 hour 1 minute and 15 seconds)
SetVar "[tcStart]" "3675"
... refresh rate (number of seconds between updates)
SetVar "[tcRefresh]" "1"
... ending value (stop count when this value is reached)
SetVar "[tcStop]" "1"
... variable to force termination before [tcStop] is reached
SetVar "[tcEndIt]" "False"
... subroutine to be called when display is stopped
... leave blank if not required
SetVar "[tcDoneRoutine]" ""
...
... now start the display
TimerStart "tc" "1000*[tcRefresh]"
In this case, the count down will begin at 1:01:15 … refresh every 1 second … and if not forced earlier, stop at 0:00:01 … and will not trigger any external subroutine when terminated.
Comments
Tony_Kroos
If “[tcStart]” “” “[tcStop]” – operator is missing
Tony_Kroos
If “[tcDoneRoutine]” “” “” also.
Gaev
Tony:
Thanks for catching the errors … these articles were copied from my website (html) pages … looks like these two commands were not properly translated when I pasted the content into this (WordPress manged) blog post.
The first command should have had a “less than” operator and the second should have had a “not equal” operator (which in VisualNeo Win is a “less than” sign followed by a “greater than” sign).
I can not edit the post since it is already in Published state, but I will ask Luis if it can be “unpublished” … so others (who do not read all the comments) do not encounter the same errors.