Page 1 of 1

Loop counting backward

PostPosted: Wed Feb 01, 2017 10:40 am
by carlos torres
Dear forum members

TIA

How can I design a loop counting backward?
I'll appreciate anyhelp

regards
carlost

Re: Loop counting backward

PostPosted: Wed Feb 01, 2017 11:54 am
by mishem
Code: Select all
SetVar "[n]" "-10"

Loop "[n]" "0" "[i]"
 SetVar "[n]" "[n]+1"
 SetVar "[List]" "[List][n][#13]"
 AlertBox "" "[List]"
EndLoop

Re: Loop counting backward

PostPosted: Wed Feb 01, 2017 12:02 pm
by mishem
OR

Code: Select all
SetVar "[n]" "10"

Loop "-[n]" "0" "[i]"
  If "[i]" "<" "0"
     StrDel "[i]" "1" "1" "[num]"
    Else
     SetVar "[num]" "[i]"
  EndIf
 SetVar "[List]" "[List][num][#13]"
 AlertBox "" "[List]"
EndLoop

Re: Loop counting backward

PostPosted: Wed Feb 01, 2017 3:27 pm
by Gaev
carlost:

Try this ...
Code: Select all
SetVar "[countFrom]" "10"
SetVar "[countTo]" "0"

Loop "[countFrom]" "[countTo]" "[currentValue]"
     AlertBox "currentValue" "[currentValue]"
EndLoop

Re: Loop counting backward

PostPosted: Wed Feb 01, 2017 6:31 pm
by mishem
It turns out everything a lot easier.
One hundred years live - and learn a century. :)

Re: Loop counting backward

PostPosted: Thu Feb 02, 2017 6:40 am
by virger
Code: Select all
Tray #1
setvar "[flg]" "0"
while "[flg]" "=" "0"
    .....
endwhile

Tray #2
setvar "[end]" "1234"
setvar "[n]" "1"
setvar "[flg]" "0"
while "[flg]" "=" "0"
    math '[n]+1" "" "[n]"
    .-.-.-.-.-.-.-.-
    if "[n]" "=" "[end]"
        exitwhile
    endif
.....
endwhile

Try#3
loop "0" "1" "[c]"
    ....
    setvar "[c]" "0"
endloop

Re: Loop counting backward

PostPosted: Mon Feb 06, 2017 7:57 am
by carlos torres
Thanks to every body for your quick answer.

mishem, gaev & virger

I was so thick-headed to code it.

regards
carlost

Re: Loop counting backward

PostPosted: Mon Feb 06, 2017 11:19 pm
by StarterPack
Insert this code in a Timer (In Timer Settings "Stop timer after one execution" must be uncheck)
In TextEntry ( [Countdown] ) you can put any number, but in this case i add 10

Math "[Countdown]-1" "" "[Countdown]"
If "[Countdown]" "=" "0"
AlertBox "" "Countdown Finished!"
TimerStop "Timer1"
SetVar "[Countdown]" "10"
Else
EndIf

Now add a button (Start Timer), or in page properties to start Timer
TimerStart "Timer1" "1000"

You can "PAUSE" the timer by adding another button (Pause)
TimerStop "Timer1"


or


You can add a Simple Text object and in General you add {Countdown]
and in page properties you can add this code

SetVar "Countdown" "10"
TimerStart "Timer1" "1000"