Hi, how do I execute the loop by step with a one-button condition using for / next or while

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Hi, how do I execute the loop by step with a one-button condition using for / next or while

Post by jairpinho »

Hi how do i advance the search with a button on a loop using for / next or while


DO WHILE npos != 5
x1:= x1+10
y1:= y1+15


mathematica.text_1.value := x1 // tempo decorrente
mathematica.text_2.value := y1 // valor desejado em base de tempo
mathematica.text_3.value := npos // tempo decorrente

if pos == .T.
npos += 1
endif

enddo
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: Hi, how do I execute the loop by step with a one-button condition using for / next or while

Post by BeGeS »

jairpinho wrote: Tue Aug 15, 2017 1:27 am Hi how do i advance the search with a button on a loop using for / next or while


DO WHILE npos != 5
x1:= x1+10
y1:= y1+15


mathematica.text_1.value := x1 // tempo decorrente
mathematica.text_2.value := y1 // valor desejado em base de tempo
mathematica.text_3.value := npos // tempo decorrente

if pos == .T.
npos += 1
endif

enddo
I tried, but there was no way for the process to stop on a button, I just made it appear and disappear. (I'm a rookie, as you can see :? ).

But an interim solution is this:

Code: Select all

   IF ! MSGYESNO("   npos="+STR(npos,1)+"       Prosseguir (Sim ou Não) ?")
      EXIT
   ENDIF
   npos +=1
To do it right you have to look at how MSGYESNO works and apply it to a button.

* * * * * * * * * * * * * * * * * *

Lo he intentado, pero no había manera de que el proceso se parase en un boton, solo he conseguido que este apareciese y desapareciese a conveniencia. (Soy novato, como puedes comprobar :? ).

Pero una solución para salir del paso es esta:

Code: Select all

   IF ! MSGYESNO("   npos="+STR(npos,1)+"      Continuar ?")
      EXIT
   ENDIF
   npos +=1
Para hacerlo bien hay que mirar cómo funciona MSGYESNO y aplicarlo a un botón.
I get by with a little help from my friends
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Hi, how do I execute the loop by step with a one-button condition using for / next or while

Post by serge_girard »

Jair,

In the main:
lSTOP := .f.

+

@ 600,10 BUTTON Start_STOP ;
CAPTION 'Cancel' ;
WIDTH 80 ;
HEIGHT 30 ;
ACTION {lSTOP := .T. } ;
FONT "Arial" SIZE 09 ;
TOOLTIP "Stop searching " ;
FLAT

Before the loop:
lSTOP := .F.

In the loop:
WHILE ..
DO EVENTS
IF lSTOP
EXIT
ENDIF
ENDDO

This I use to stop loops!

Serge
There's nothing you can do that can't be done...
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: Hi, how do I execute the loop by step with a one-button condition using for / next or while

Post by BeGeS »

Serge, that button interrupts a process, but I think it's not what Jairpinho wants.
It is that in each step (before or after npos += 1) the process stops and ask if you want to continue.
Excuse me both if I am wrong, but I have interpreted it thus, since it makes no sense to stop an accountant of 1 to 5, something impossible even for Lucky Luke.

* * * * * * * * * * * * * * * * *

Serge, ese botón interrumpe un proceso, pero creo que no es lo que quiere Jairpinho.
Se trata de que en cada paso (antes o después de npos +=1) el proceso se detenga y pregunte si se desea continuar.
Disculpadme los dos si me equivoco, pero yo lo he interpretado así, ya que carece de sentido parar un contador de 1 a 5, algo imposible incluso para Lucky Luke.
I get by with a little help from my friends
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Hi, how do I execute the loop by step with a one-button condition using for / next or while

Post by esgici »

@Serge and BeGes

Congrats, you are understand the question.

Regards
Viva INTERNATIONAL HMG :D
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: Hi, how do I execute the loop by step with a one-button condition using for / next or while

Post by BeGeS »

esgici wrote: Wed Aug 16, 2017 9:10 am @Serge and BeGes

Congrats, you are understand the question.

Regards
:roll:

Well, maybe he wants to draw a sloping line in the cartesian plane small step to small step...

:geek:

Pues a lo mejor quiere dibujar una recta inclinada en el plano cartesiano pasito a pasito...

:)
I get by with a little help from my friends
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Hi, how do I execute the loop by step with a one-button condition using for / next or while

Post by esgici »

BeGeS wrote: Wed Aug 16, 2017 10:01 am ...
Well, maybe he wants to draw a sloping line in the cartesian plane small step to small step...
...
I just meant to say "I do not understand" :?

BTW
... to draw a sloping line in the cartesian plane small step to small step...
reminded me this:

http://www.hmgforum.com/viewtopic.php?f=9&t=2387

Regards.
Viva INTERNATIONAL HMG :D
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: Hi, how do I execute the loop by step with a one-button condition using for / next or while

Post by BeGeS »

I was kidding... :mrgreen:

I imagine there are more sophisticated tools for drawing.

Jair does not want a line. He wants a button (or two :roll: ) inside a WHILE / END loop that always interrupts and allows to continue or cancel.
I get by with a little help from my friends
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: Hi, how do I execute the loop by step with a one-button condition using for / next or while

Post by jairpinho »

BeGeS wrote: Wed Aug 16, 2017 3:34 pm I was kidding... :mrgreen:

I imagine there are more sophisticated tools for drawing.

Jair does not want a line. He wants a button (or two :roll: ) inside a WHILE / END loop that always interrupts and allows to continue or cancel.

I even want a button to interrupt and continue a for or while, thanks to everyone for the tips but they do not answer as I need
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Hi, how do I execute the loop by step with a one-button condition using for / next or while

Post by serge_girard »

Jair,

It is difficult to understand/see exactly what you want. May be this?

Code: Select all

#include "hmg.ch"


lPAUSE := .f.

DEFINE WINDOW mathematica   ;
	AT 0,0	   ;
	WIDTH  750	;  
	HEIGHT 800	;
	ICON  ""	;
 	TITLE 'mathematica '  ;
	NOMAXIMIZE	;
	NOSIZE		;      	
	BACKCOLOR WHITE ;
   MAIN

	ON KEY ESCAPE			ACTION { mathematica.Release }

	@ 10,10 LABEL text_1 ;
		VALUE " " ;
		WIDTH 500 ;
		HEIGHT 20 ;
		BACKCOLOR GREEN;
		FONT 'Arial' SIZE 9		;

	@ 40,10 LABEL text_2 ;
		VALUE " " ;
		WIDTH 500 ;
		HEIGHT 20 ;
		BACKCOLOR YELLOW;
		FONT 'Arial' SIZE 9		;

	@ 70,10 LABEL text_3 ;
		VALUE " " ;
		WIDTH 500 ;
		HEIGHT 20 ;
		BACKCOLOR ORANGE;
		FONT 'Arial' SIZE 9		;

   @ 120,10 BUTTON START ;
      CAPTION 'Start loop' ;
      WIDTH 80 ;
      HEIGHT 30 ;
      ACTION JLOOP();
      FONT "Arial" SIZE 09 ;
      TOOLTIP "Start " ;
      FLAT

   @ 160,10 BUTTON PAUSE ;
      CAPTION 'Pause' ;
      WIDTH 80 ;
      HEIGHT 30 ;
      ACTION {lPAUSE := .T. } ;
      FONT "Arial" SIZE 09 ;
      TOOLTIP "Pause " ;
      FLAT

END WINDOW
CENTER WINDOW   mathematica
ACTIVATE WINDOW mathematica

 

FUNCTION JLOOP()
/**************/
lPAUSE := .F.
x1    := 1
y1    := 2
npos  := 0

DO WHILE npos != 5
   x1:= x1 + 10
   y1:= y1 + 15

   DO EVENTS
   IF lPAUSE
      lPAUSE := .F.
      npos += 1
      MSGINFO('PAUSE')
   ENDIF

   mathematica.text_1.value := x1   // tempo decorrente
   mathematica.text_2.value := y1   // valor desejado em base de tempo
   mathematica.text_3.value := npos // tempo decorrente

enddo 

Serge
There's nothing you can do that can't be done...
Post Reply