Page 1 of 1

stop executing the loop

Posted: Thu Oct 11, 2018 5:42 pm
by miroslav.maričić
SRB:
Da li neko može da mi pomogne u sledećem problemu:
Definisao sam prozor Form_1, u njemu Grid_1, u gridu Toolbar_1, a u toolbaru dugmad Button_1, Button_2,...Button_n.
Klikom na jedno od dugmadi pokreće se procedura u kojoj je jedna FOR-NEXT petlja. Želeo bih da korisnik može, pritiskom na neki taster na tastaturi (npr. ESC), zaustavi izvršavanje petlje, pa da ga program pomoću MsgYesNo() funkcije pita da li želi da prekine izvršavanje ili da nastavi.
Pokušao sam sa funkcijom INKEY(), zatim GetAsincKeyState(), GetKeyState() ali bez uspeha. Da li može neko da me posavetuje kako da rešim problem?
P.S. Ne govorim engleski, ovaj post mi je prevela koleginica iz škole ;)

EN:
Can anyone help me with the following problem:
I defined the window Form_1, Grid_1 in Form_1, Toolbar_1 in Grid_1, and the buttons in the toolbar: Button_1, Button_2,...Button_n.
By clicking one of the buttons the procedure with a FOR-NEXT loop starts. I would like that the user can stop executing the loop by clicking one of the keys on the keyboard (for example ESC), and that the program using MsgYesNo() function asks the user if he wants to stop or to continue executing the loop.
I tried the INKEY() function, then the GetAsincKeyState() and the GetKeyState() but with no result.
Can anyone give me a piece of advice how to solve this problem?

Re: stop executing the loop

Posted: Thu Oct 11, 2018 6:03 pm
by Rathinagiri
You try like this:

Code: Select all

   public lStop := .f.
   define window form_1 .....
   ------
      on key escape action confirmyesno()
   end window

function confirmyesno
   if msgyesno( 'Are you sure to stop?')
         lStop := .t.
   endif
return nil

procedure forloop

for i := 1 to n
   DO EVENTS
   .....
   if lStop
      .... You can stop here!
   endif
next i
Please note the DO EVENTS inside the For...Next Loop.

Re: stop executing the loop

Posted: Thu Oct 11, 2018 10:49 pm
by SALINETAS24
Hola miroslav.

Te paso un enlace donde se trato de varias forma la detección y solución a tu problema.

http://www.hmgforum.com/viewtopic.php?f=24&t=5770

Un saludo,

Re: stop executing the loop

Posted: Fri Oct 12, 2018 9:13 am
by miroslav.maričić
СРБ:
Захваљујем се колеги Rathinagiri на помоћи. Код који ми је написао - ради одлично! Још једном му се пуно захваљујем. Такође, велико хвала и SALINETAS24 на помоћи.

ENG:
I thank Mr Rathinagiri for helping. The code he wrote me - he works great! Once again I thank him very much. Also, thank you very much and Mr. SALINETAS24 for help.
Translated into English with the help of Google :D

Re: stop executing the loop

Posted: Fri Oct 12, 2018 5:47 pm
by Rathinagiri
You are welcome!