Android Question AnotherProgressBar.ValueChangePerSecond

PhilipBrown

Active Member
Licensed User
Longtime User
ValueChangePerSecond moves the bar of AnotherProgressBar but it does not change Value:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")

    AnotherProgressBar1.ValueChangePerSecond = -10

    If FirstTime = True Then
        Timer1.Initialize("Timer1", 100)
        Timer1.Enabled = True
    End If
End Sub

Sub Timer1_Tick
    Dim val As Int
    val = AnotherProgressBar1.Value
    Log(val) 'value logged never changes
End Sub

Also the way the bar moves seems contrary to expectations.
If ValueChangePerSecond is positive then the bar shrinks, if negative then it grows.
 

William Lancee

Well-Known Member
Licensed User
Longtime User
The code below moves the bar from 50% to 25% at a rate of 10% per second and then 2.5 seconds later moves it back.
Negative numbers for change are invalid (and confusing).

B4X:
    AnotherProgressBar1.ValueChangePerSecond = 10
    AnotherProgressBar1.Value = 50
    AnotherProgressBar1.Value = 25
    Sleep(2500)
    AnotherProgressBar1.Value = 50
 
Last edited:
Upvote 0

Jorge M A

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    AnotherProgressBar1.Value = 100
    'AnotherProgressBar1.ValueChangePerSecond = -10 Dont Use This!

    If FirstTime = True Then
        Timer1.Initialize("Timer1", 100)
        Timer1.Enabled = True
    End If
End Sub

Sub Timer1_Tick
    Dim val As Int = AnotherProgressBar1.Value
    Log(val) 'value logged
    AnotherProgressBar1.Value = AnotherProgressBar1.Value - 1 'Subtract your desired value
    If AnotherProgressBar1.Value <= 0 Then
        Timer1.Enabled=False
        AnotherProgressBar1.Value = 0
        AnotherProgressBar1.SetValueNoAnimation(0)
    End If
End Sub
 
Upvote 0

PhilipBrown

Active Member
Licensed User
Longtime User
The code below moves the bar from 50% to 25% at a rate of 10% per second and then 2.5 seconds later moves it back.
Negative numbers for change are invalid (and confusing).

B4X:
    AnotherProgressBar1.ValueChangePerSecond = 10
    AnotherProgressBar1.Value = 50
    AnotherProgressBar1.Value = 25
    Sleep(2500)
    AnotherProgressBar1.Value = 50
Thanks William. In fact I find you need to allow enough time for the bar to move. If not, the bar will never reach the target.
 
Upvote 0
Top