How do I stop a Do Until …/… Loop ?

Maybe a stupid question, but…

If UserCancelled Then Exit does not seems to work in a Do Until <condition …/… Loop.

Is it possible to go out of this kind of Loop ?

[quote=398076:@Emile Schwarz]Maybe a stupid question, but…

If UserCancelled Then Exit does not seems to work in a Do Until <condition …/… Loop.

Is it possible to go out of this kind of Loop ?[/quote]

Exit should work. Are you sure UserCancelled is true?

Thanks Sasha.

I am sure that I pressed cmd-. (and keep it pressed) for way too long (more than one ful loop) on my mac OS laptop. I add an entry for each loop in a Listbox (so I know the download is still working, between others).

I use Force Quit, but I have to set the download base URL, date start and end / left the log .txt file “as is” and I do not like that.
(sometimes I use a wrong date, sometimes the wrong URL, etc.)

What about

Do Until i As Integer = 10 Or UserCancelled = True

Loop

[quote=398078:@Emile Schwarz]Thanks Sasha.

I am sure that I pressed cmd-. (and keep it pressed) for way too long (more than one ful loop) on my mac OS laptop. I add an entry for each loop in a Listbox (so I know the download is still working, between others).

I use Force Quit, but I have to set the download base URL, date start and end / left the log .txt file “as is” and I do not like that.
(sometimes I use a wrong date, sometimes the wrong URL, etc.)[/quote]

I do not trust Keyboard only actions in Xojo (can’t explain why, but…)

Maybe you could use the Keyboard to flip a Switch (Toggle Button, CheckBox, …) in your App and check the Switch State in your Loop? That would add a visual indication to your Stop Signal too. :slight_smile:

Thank you Derk.

i As Integer = 10
I = 365 or 366, but I can download more than one year at a time…

UserCancelled = True
I may check that one!

Sasha:
Yes. I have to add a Thread, put the download code in it (or something) and add a CheckBoc (Stop at the end of the Loop) and code to … stop at the end of the loop, so in case of error or simple testing, I can stop the application gracefully.

Thanks for the feedback.

That isn’t a ‘Yes’ :slight_smile:

IF usercancelled IS true, and EXIT doesn’t work, try

if usercancelled then i = 10

Thank you Jeff.

I do not understand how this can work. To compile that I have to dim i first.

That was intended to be a yes ! :wink:

I like to recommend to do:

If UserCancelled Then Break Exit End If

in the Debugger and verify that UserCancelled is really true.

You mean I have to press something else ?

(I have 270 files to download until I can test or to Force Quit now)

No, i just do not know what goes wrong. But i do know, that an Exit exits a Do…Loop :smiley:

Personally, I like to do things like this in a thread, with a ‘cancelled’ property on the thread. In the progress dialog, I have a cancel button and clicking that button, simply sets the ‘cancelled’ property to true.

Same here :wink:

I will come back to this quest after a nap; now it is 37° (Celcius) outside and I have to go back home…

Sam: thank you. I have to do that (after the so called nap). I pushed that for “tomorrow” probably some days too many :wink:

I am sure Sam is referring to everything which is not 100% under your control (like Network Communication, Filesystems, … ) and could block execution from continue or dramatically slow down th UI. I needed 5+ years to not only learn this lesson but to live by it (most times). :smiley:

#Pragma BackgroundTasks False

Yes, perfect for when you like to make your UI freeze for sure :wink:

I mean it more like, that’s a possibility. But UI updating or requests from UI stuff inside a loop makes it no better.

Unless your loop is in a thread, the Keyboard action will not be processed and UserCancelled will not be set to True until sometime after your loop finishes. Your loop effectively blocks all keyboard actions while it runs. Put your loop in a thread and yield time back to the main thread often enough to get a timely response to the user hitting the cancel key.

Yup.
And if you want an example of a process you can’t stop, try clicking cancel while compiling a Xojo app!!!

[quote=398139:@Jeff Tullin]Yup.
And if you want an example of a process you can’t stop, try clicking cancel while compiling a Xojo app!!![/quote]

Tell me something; accidently pressing the build button and compile all 3 platforms on a major project cloud result in a delay of over 1hour depending on some factors. That’s not really RAD or is it?

Having a cancel button that doesn’t work is a real issue.