PDA

View Full Version : ThinBasic Design question - ever running loop - how to stop ?



chris_bdnsee
14-03-2009, 20:16
Hello,
i am rather new to TB - but for sure love it from day one....

While I am speeding up my roosty skills in basic I have one question, which is more related to design.

I have a simple form with two buttons (not using callbacks - yet).

One button starts a loop which runs forever (while loop), the other button contains code to intercept the global variable from the loop of button 1.

I have added a sleep statement in buttoon1 and a couple of doevents.

however, the doevents cleary help other apps to get some time to process, but I am not able to get thinbasic to react on a click on the button2 (which would stop the loop of button1).
The only way to end the process is by closing down in the taskmanager.

Now the question.
How do I need to design both code fragments that I could intercept a loop from an other piece of code.

Thank you for any idea.....

best regards

Christian

Petr Schreiber
14-03-2009, 22:07
Hi Chris,

welcome to ThinBasic forums!

Could you please show us code, it is always easier to help this way.
I am not sure never ending loop is good approach in any dialog based app, maybe timers could help.

What I must recommend in first place is to go callback way - easier to manage and much, much more responsive than old While/Wend way.


Petr

chris_bdnsee
14-03-2009, 22:30
Petr,
many thanks for your prompt reply.
Fair comment - I will try to enhance to callback functions and retry.
If I don't get this working I will post the script.

best

Christian

Michael Clease
15-03-2009, 00:33
One button starts a loop which runs forever (while loop), the other button contains code to intercept the global variable from the loop of button 1.


Hello Christian

One simple question do you check that the second button has been pushed in that new loop you created.

ErosOlmi
15-03-2009, 11:32
Ciao Christian adn welcome to thinBasic ommunity.

As Petr said, the best way to go is using dialogs callbacks.
The old way of handling dialog messages using WHILE/WEND loops and getting messages with GetMessage function will be abandoned in future thinBasic versions.

Michael gave you an example on how to achieve what you need using WHILE/WEND loops.

Here I'm giving you a possible solution using dialogs callbacks and one timer.

Hope this can help.
Ciao
Eros

chris_bdnsee
15-03-2009, 20:13
WOW,
a special thanks to all of you for sharing your advanced knowledge with me....

best regards

Christian