I had the same problem...here's how I did it
I wanted as much CPU for the processing
minimize event processing
and only to test the STOP button occasionally
(example may not sytatically correct)
1) Have a global boolean
2) Have a click button to 'stop'
3) Inside your computations Increment an integer
and every million increments perform a WAIT
4) The WAIT will let the interpreter catch events
and if the stop button was pressed ACTIVE is set TRUE
5) somewhere else in you computations look for ACTIVE = TRUE to quit.
DIM active AS BOOLEAN 'this is a global var
'gets set TRUE when the click button pressed
- - - - - - -
active = TRUE
- - - - - - - - - -
dim i as integer
' you want to increment i often inside inner loops
'at some part of the code loops that is executed less frequently
(like after NEXT statements)
IF i > 1000000 THEN 'only when i reached 1 million (pick a number you like)
WAIT 0.1 'this will see if STOP is being pressed
IF ACTIVE = TRUE then GOTO abort_mission 'I used a goto in some programs or BREAK
- - - - - - -
---------- Original Message -----------
From: serge bouc <***@free.fr>
Sent: Thu, 28 Sep 2006 14:02:47 +0200
Subject: [Gambas-user] How to interrupt a loop ?
Post by serge bouc
My problem is now the following : I have a form in Gambas,
with a button called "compute". When this button is clicked,
the program executes "compute_click()", which is essentially
a loop where a computation is done, which may be rather long,
depending on some other parameters of the program.
So I would like to have the possibility of interrupting this computation,
with a click, or a keypress, or whatever. But it seems that once
the computation loop has started, all the events I could use
are inactive (the mouse clicks are no longer seen, nor the keys
pressed, even the timer events), until the loop has terminated.
I imagine I am missing something here. I have tried to define
a new EVENT I could RAISE at some point in the loop, but
I didn't succeed, and I confess I don't understand Gambas
documentation on this subject.
So the only thing I can do at the moment is stop the program by
closing its window, and waiting for KDE to kill the application.
Of course, this is definitely not a good solution... :-(
Thanks for any suggestion.
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
Gambas-user mailing list
------- End of Original Message -------