stop executing the loop

HMG Samples and Enhancements

Moderator: Rathinagiri

Post Reply
User avatar
miroslav.maričić
Posts: 7
Joined: Sat Mar 23, 2013 11:38 pm
DBs Used: DBF
Location: Serbia
Has thanked: 6 times

stop executing the loop

Post by miroslav.maričić » Thu Oct 11, 2018 5:42 pm

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?

User avatar
Rathinagiri
Posts: 5243
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 162 times
Been thanked: 161 times
Contact:

Post by Rathinagiri » Thu Oct 11, 2018 6:03 pm

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.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
SALINETAS24
Posts: 173
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Has thanked: 2 times
Been thanked: 3 times

Post by SALINETAS24 » Thu Oct 11, 2018 10:49 pm

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,

User avatar
miroslav.maričić
Posts: 7
Joined: Sat Mar 23, 2013 11:38 pm
DBs Used: DBF
Location: Serbia
Has thanked: 6 times

Post by miroslav.maričić » Fri Oct 12, 2018 9:13 am

СРБ:
Захваљујем се колеги 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

User avatar
Rathinagiri
Posts: 5243
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 162 times
Been thanked: 161 times
Contact:

Post by Rathinagiri » Fri Oct 12, 2018 5:47 pm

You are welcome!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

Post Reply