B4J Question Progress bar usage

I wrote an application that display a main panel in which the user locate a SQLite DB.
then I have a listview in which I show a list of the tables.
the user select which tables he want. Then I want to export them to EXCEL sheets.
All the above is written and work.
I have a code module in which I have a sub that is called by the main.
in this Sub I have a loop that run on the list of tables selected.
and for each he calls another Sub that export the specific table to excel.
I created a form for the progress bar. and put on it 2 labels and 2 progress bars.
for this I created a Class module in which I init and handle the Progress Bar.
I have a Sub that show the form another that close it and one that update the label and progress of the relevant bar.
I selected 2 tables that have about 7200 records each. The process complete excel created. But progress bar did not show at all.
I will appreciate any help solving this issue.
 

Attachments

  • SQLite2Xl.zip
    9.7 KB · Views: 212

Erel

B4X founder
Staff member
Licensed User
Longtime User
The progress bar will only be updated when the main thread is free to process the message queue.

You need to first find out which step is slow. Whether it is the SQL related code or the Excel creation code. If it is the SQL code then you should switch to the asynchronous methods. My guess is that the problem is in the Excel code.
If so then you will need to create to convert the tables one by one and use CallSubDelayed to start processing the next table.

For example:
B4X:
Sub ConvertTable (i As Int)
 'get table i from a list or from any other collection
 'export to Excel
 If i < NumberOfLists Then CallSubDelayed2(Me, "ConvertTable", i + 1)
End Sub
 
Upvote 0
In fact no one is slow. I selected 2 tables each one with 7200 records it completed in a few seconds. But would like to run the program on large tables. May be 160000 or even bigger. In any case sure the SQL is faster !. The problem is that I am doing something wrong since I can't see the progressbar for displayed at all.
You can open the zip file and run the application select any SQLIte DB that you have and you will see. It complete and display the final message box.

By the way I noticed also that when I disable a Button in the code it is not functional but you don't have any visual indication. I added for it code to set the Alfa to 0.5f.
But it should be done by the enable=false.
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
The UI will not be updated until the main thread is free to process the internal message queue. This is why you need to split the large task into smaller tasks and chain them with CallSubDelayed.
Hummm, I have used the CallSubDelayed in this exact same issue but limited success (some progressbar or indicator update).
My issue is jCharts is adding to (many) series and won't update the main thread until it is done. This can take many seconds with a large set of XY points. So, with the absence of an update progress event, the progressindicator won't get updated until it hits the 'Visible = false' line - after all series have been populated. Not a deal breaker, but you don't want users clicking buttons while the system is at work under the hood (providing no updated visual feedback). My 2 pesos...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
So, with the absence of an update progress event
It is not related to any missing event. The UI cannot be updated until the main thread is free to process the message queue.

If you are able to reproduce it in a small project then please upload it and we will help you solve it with CallSubDelayed.
 
Upvote 0
Top