Can a ProgressBar be used for a timer?

PharCyDeD

Active Member
Licensed User
Longtime User
I want to use a progress bar that ticks down from 100 by -1 a second. I have this code:

Globals:

B4X:
Dim pbTimeLeft As ProgressBar

Activity_Create:

B4X:
pbTimeLeft.Initialize(pbTimeLeft)
   pbTimeLeft.Progress = 100

Timer:
B4X:
Sub Timer1_Tick
      
   countDown = countDown - 1
   lblCountDown.Text = countDown
   
   pbTimeLeft.Progress = pbTimeLeft.Progress - 1
   
   If countDown=0 Then
      Timer1.Enabled= False
   End If 
   
End Sub

It is not working though? It is purely for visual purposes as the real count is kept by the countDown variable, but I still would like to use it.
 

Ricky D

Well-Known Member
Licensed User
Longtime User
I haven't tried this but maybe put a DoEvents in the timer event?

regards, Ricky
 
Upvote 0

PharCyDeD

Active Member
Licensed User
Longtime User
I am not sure what I am doing wrong I did add DoEvents to the timer, but that didn't work either. Am I creating the progressbar correctly? Because no matter what I set .progress to it does not reflect the progress in the app.
 
Upvote 0

PharCyDeD

Active Member
Licensed User
Longtime User
Yes that is exactly what I am looking for, but I don't understand why it won't work within my project. I will do some digging on this to see what I can find.
 
Upvote 0

PharCyDeD

Active Member
Licensed User
Longtime User
Well apparently you can't use ProgressBar1.Initialize in the activity create area when trying to do this. Not sure why, but when I removed that it worked fine. Thanks!
 
Upvote 0
Top