60 seconds timer

Gekornro

Member
Licensed User
Longtime User
Hi,

I've completed my first app and it works really well. I wanted to add a timer to it that counts up to 60 seconds. I thought that would be an easy feat... But I've no luck so far. I'm NOT an experienced programmer so it's all still new to me..

B4X:
Sub Activity_Create(FirstTime As Boolean)
    
Dim Trial As Boolean
Trial = True 

Activity.LoadLayout("Setup") 
pw.KeepAlive(True) 

If Trial = True Then

     Timer1.Initialize("Timer1", 1000)
     Timer1.Enabled = True

End If

End Sub


Sub Timer1_Tick

countup=countup + 1
Label3.Text= countup 

If countup=60 then
Timer1.Enabled= False
    NRotationA_Click
    NRotationB_Click
End If 
 
End Sub


What I'm trying to achieve here is a counter that counts up to 60 seconds. Once it hits 60 seconds it simulates 2 button clicks.

All that happens when I compile this is that it is stuck on 1....

Where have I gone wrong? Perhaps several places :)

Countup is declared as Int in Process_Globals.
 

derez

Expert
Licensed User
Longtime User
A declaration of countup should be in the globals:
B4X:
Dim countup as int
also it will be a good idea to set it to zero before the timer starts to tick...
 
Upvote 0

Gekornro

Member
Licensed User
Longtime User
A declaration of countup should be in the globals:
B4X:
Dim countup as int
also it will be a good idea to set it to zero before the timer starts to tick...

Yep, that did the trick! So simply, but I still missed it. Don't know why I declared it in Global_Process....oh well.

And the timer does now start at 0 to :)
 
Upvote 0
Top