Android Question why does this not work

Mohammed Jamil Younis

New Member
Licensed User
Longtime User
Hi in the startup code I have following code what I want is to display the count in the label as it progress but I get a pause and then 1000 displayed have tried adding delays but just get longer pause then final count displayed thank you for help

dim n as int
For n = 0 to 1000
Label1.text = "Count = " & n
Next
 

LucaMs

Expert
Licensed User
Longtime User
Try so:
B4X:
dim n as int
For n = 0 to 1000
Label1.text = "Count = " & n
DoEvents
WaitFor(500)
Next

B4X:
Sub WaitFor(Milliseconds As Int)
Dim s As Long
s = DateTime.Now
Do While DateTime.Now < s + Milliseconds
Loop
End Sub

If DoEvents is not enough, you should try Label1.Invalidate or Activity.Invalidate
 
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
The code LucasMS showed will work and do what you want.

I personaly, use a timer instead of a pause.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
B4X:
Sub Process_Globals
   Dim timer1 As Timer   
End Sub

Sub Globals
   Private Label1 As Label
   Private counter As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)   
   
   Label1.Initialize("")
   Activity.AddView(Label1,20dip,20dip,60dip,30dip)
   
   timer1.Initialize("timer1",1000) ' 1000 = 1 sec
   timer1.Enabled = True

End Sub

Sub timer1_tick
   
   counter = counter + 1
  Label1.text = "Count = " & counter
   
End Sub
 
Upvote 0
Top