Just keep practicing here. Is there any way to display a box with a message while it’s processing something? I tried to do a window to show a text box with a global variable that I can change the value of the variable and be able to call up the window to display the message. What I did was at the beginning of a button click (action) I want to show the window and at the end of the same “Action”, I want to hide it. I am copying some records to a tmp database that I notice it takes about 5 seconds on slower computers and I want to display “Processing” until it finishes copying.
I tried the progress bar but it looks like it doesn’t show until the process is done even though I told it to show at the beginning before the copying of the records.
A long running loop etc. will freeze your IDE. You need to work with a Xojo Timer to update your IDE in this case.
Thank You Jeannot,
I did it that way and it works good. I appreciated.
You can also use progressbar.refresh after you changed the value of the progressbar. That will show the updated value directly.
Not if you have a long running loop, that will freeze your code until it is finished. Depends on your loops and the duration, of course and the platform too. For a WebApp it is almost always the case that it will “freeze”.
I use Xojo desktop and with a long loop I use the .refresh statement and I see that the progressbar is updated with every value change. Maybe it is different with web apps.
Yes and no. It really depends on what you are doing. Xojo is not multithreaded. If you block your main thread with something running for a very long time (or simulating that behavior), nothing has a chance to interact with your UI to the extend that on macOS the ugly balloon might show up.
Try the following. Put a button and a progressbar in your app:
Under Action of PushButton1 add the following code:
for x as integer = 51 to 100
'Have fun uncommenting the line below ;-)
ProgressBar1.Value = x
That is working fine and updating the progressbar. Now uncomment the app.sleepCurrentThread(300) there it is the colorful macOS balloon.
One would assume, that within this loop there is a short wait for 300ms but then the next refresh will fire. But no, the next refresh will happen after the loop as finished, so after 50 * 300 ms.
Replace the sleepCurrentThread statement by a long-running call of a method, it will be exactly the same, that’s when timers are needed. Though even with timers, you have often to ensure that your long-running routines will wait from time to time, so that that the timer can react.
In general it is fair to predict, that sooner or later you will remember this post ;-). It is one of this challenges where people are struggling when it happens the first time in their code.