How to break out of a do loop until by using another button

Win10 LO 7.3.7.3 HSQL 2.61

Hello,

I have a form which I want to autoclose after a certain time using a modified macro given some time ago.

Sub formExitTimer
rem get the secs from settings form
rem need a way to interrupt the loop exit if cancel button is pressed
iSeconds = 600
t = timer +iSeconds
do
loop until t <= timer
msgbox “now do exit procedures…”
'auto save, close stuff…
exit sub
End Sub

Code works well, no problems, I just would like to modify the code to break out of the loop if a button on the form is clicked to stop the countdown.

Thinking of using some boolean such as once the button is clicked - stp=true

Not sure how to implement this, would it be a loop in a loop sort of thing?

Appreciate any pointers, thanks

Are you sure? I don’t see anything in the loop? So this should run either once or forever.
.
To your question: If you use a countdown-loop, you may just put a second condition in the until-condition like if you can check for the state of the button directly.
In an event-driven model you need to have a routine/handler to be called, when the button is pressed, wich sets a variable to signal " button was pressed" and reference this signal in the until clause with OR
.
And if you left out something in the loop, I hope it is a wait statement, notvjust countig up/down a number…

Thanks, yes the bare bone just runs once as I did not put in the after statements. Second condition might be another solution.

The End command stops all StarBasic.
Good to know: Ctrl+Shift+Q does the same from the user interface

Sub ExitButton_Click()
    End
End Sub
1 Like

Thanks Villeroy, this oneliner is gold !