B4J Question [Solved] AnotherProgressBar - Why this strange behvior?

LucaMs

Expert
Licensed User
Longtime User
java_RFyG64E7o2.gif


B4X:
Private Sub Test
    Dim ProgrBarStep As Double
    ProgrBarStep = 100 / 789
    AnotherProgressBar1.Value = 0
    AnotherProgressBar1.Visible = True
    Sleep(0)
    For i = 1 To 789
        AnotherProgressBar1.Value = i * ProgrBarStep
        Sleep(5)
    Next
    AnotherProgressBar1.Visible = False
End Sub
(Project attached but that's all the code)
 

Attachments

  • AnotherProgressBarTest.zip
    2.4 KB · Views: 36
Last edited:
Solution
Solved, using:

AnotherProgressBar1.SetValueNoAnimation(0)

B4X:
Private Sub Test
    Dim ProgrBarStep As Double
    ProgrBarStep = 100 / 789
    AnotherProgressBar1.SetValueNoAnimation(0) '<---
    AnotherProgressBar1.Visible = True
    For i = 1 To 789
        AnotherProgressBar1.Value = i * ProgrBarStep
        Sleep(5)
    Next
    AnotherProgressBar1.Visible = False
End Sub

LucaMs

Expert
Licensed User
Longtime User
Solved, using:

AnotherProgressBar1.SetValueNoAnimation(0)

B4X:
Private Sub Test
    Dim ProgrBarStep As Double
    ProgrBarStep = 100 / 789
    AnotherProgressBar1.SetValueNoAnimation(0) '<---
    AnotherProgressBar1.Visible = True
    For i = 1 To 789
        AnotherProgressBar1.Value = i * ProgrBarStep
        Sleep(5)
    Next
    AnotherProgressBar1.Visible = False
End Sub
 
Last edited:
Upvote 0
Solution

aeric

Expert
Licensed User
Longtime User
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Private AnotherProgressBar1 As AnotherProgressBar
    Private ProgrBarStep As Int
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
End Sub

Sub Button1_Click
    ProgrBarStep = (450 / 789) * 100
    AnotherProgressBar1.Value = ProgrBarStep
    AnotherProgressBar1.SetValueNoAnimation(ProgrBarStep)
    AnotherProgressBar1.Visible = True
    Sleep(0)
    Test
End Sub

Private Sub Test
    Do While AnotherProgressBar1.Value < 100
        AnotherProgressBar1.Value = AnotherProgressBar1.Value + 1
        Log(AnotherProgressBar1.Value)
        Sleep(50)
    Loop
    AnotherProgressBar1.Visible = False
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Private AnotherProgressBar1 As AnotherProgressBar
    Private ProgrBarStep As Int
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
End Sub

Sub Button1_Click
    ProgrBarStep = (450 / 789) * 100
    AnotherProgressBar1.Value = ProgrBarStep
    AnotherProgressBar1.SetValueNoAnimation(ProgrBarStep)
    AnotherProgressBar1.Visible = True
    Sleep(0)
    Test
End Sub

Private Sub Test
    Do While AnotherProgressBar1.Value < 100
        AnotherProgressBar1.Value = AnotherProgressBar1.Value + 1
        Log(AnotherProgressBar1.Value)
        Sleep(50)
    Loop
    AnotherProgressBar1.Visible = False
End Sub
No, that's not good. The number of cycles must be variable, not 100.
For example, you have to process 47 files; at the end of each single processing, you want to show the progress in the ProgressBar which, in this example, must increase its value by 47/100.
(47 which can be different, obviously, even higher than 100)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
However, SetValueNoAnimation is the solution only to avoid animating from the current value (100, usually) to zero.
Then, however, in B4J-Release I still wasn't able to get what I wanted, the ProgressBar remains empty until the end of the processing (after which I set it as not visible).
It doesn't work adding a Sleep (which would slow down processing anyway) and neither using AnotherProgressBar1.UpdateGraphics.
:oops::(


P.S. The test project works, with a simple Sleep(5), the real project does not, not even by setting very high values in Sleep.
Okay, I'll find out the problem (I hope 😄 ).
 
Last edited:
Upvote 0
Top