N nubi Member Licensed User Longtime User Feb 8, 2012 #1 Hello everybody, I'm trying to make a simple countdown timer in which on the first layout you set the time in seconds you want it to count backwards and click on a button to set it and open the next Activity. (So far so good) On the new layout of the second activity and a new layout you have two buttons (1) Start and (2) Stop. The idea is that when you press "Start" a progress bar is shown in a backwards fashion and a sound will be played (not implemented yet). If the "Stop" button is pressed the countdown should stop reinitialize and wait for the "Start" button to be pressed again. The problem I'm having is once the countdown starts after pressing "Start" the countdown does not stop until it has completed the for loop. And once it finishes neither of the buttons do anything.:BangHead: Here's my code: Code: Copy Sub btnStart_Click For I=Main.T To 1 Step -1 PBar.Progress=(C*I) ' Math so Progress Bar looks good Sleep(1000) ' Pause time for Progress Bar countdown Next End Sub Code: Copy Sub btnStop_Click I=Main.T End Sub ** I don't have any code in the subs Activity_Resume or Pause, don't know if that will affect anything. Thanks in advance.
Hello everybody, I'm trying to make a simple countdown timer in which on the first layout you set the time in seconds you want it to count backwards and click on a button to set it and open the next Activity. (So far so good) On the new layout of the second activity and a new layout you have two buttons (1) Start and (2) Stop. The idea is that when you press "Start" a progress bar is shown in a backwards fashion and a sound will be played (not implemented yet). If the "Stop" button is pressed the countdown should stop reinitialize and wait for the "Start" button to be pressed again. The problem I'm having is once the countdown starts after pressing "Start" the countdown does not stop until it has completed the for loop. And once it finishes neither of the buttons do anything.:BangHead: Here's my code: Code: Copy Sub btnStart_Click For I=Main.T To 1 Step -1 PBar.Progress=(C*I) ' Math so Progress Bar looks good Sleep(1000) ' Pause time for Progress Bar countdown Next End Sub Code: Copy Sub btnStop_Click I=Main.T End Sub ** I don't have any code in the subs Activity_Resume or Pause, don't know if that will affect anything. Thanks in advance.
stevel05 Expert Licensed User Longtime User Feb 8, 2012 #2 You should look at using a timer to drive the count down, it's then a simple case of disabling the timer and resetting the count when stop is clicked. Upvote 0
You should look at using a timer to drive the count down, it's then a simple case of disabling the timer and resetting the count when stop is clicked.
NJDude Expert Licensed User Longtime User Feb 8, 2012 #3 Better use a timer to do something like that, take a look at the attached sample, it is a very basic sample of what you are trying to achieve. I hope it will give you an idea. Attachments TimerSample.zip TimerSample.zip 7 KB · Views: 450 Upvote 0
Better use a timer to do something like that, take a look at the attached sample, it is a very basic sample of what you are trying to achieve. I hope it will give you an idea.
N nubi Member Licensed User Longtime User Feb 9, 2012 #4 SOLVED. Thank you for your suggestions and code sample. It is definitely much easier to control with the Timer. :sign0188: Upvote 0
SOLVED. Thank you for your suggestions and code sample. It is definitely much easier to control with the Timer. :sign0188: