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
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 »

Ok Serge. That must be what Jair wants. Or in any case, a very similar thing.

P.S.: I just discovered the use of DO EVENTS. ;)
I get by with a little help from my friends
User avatar
serge_girard
Posts: 3161
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 »

DO EVENTS is great, but it can interfere with other functions, so be carefull...

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_girard wrote: Mon Aug 21, 2017 6:51 am DO EVENTS is great, but it can interfere with other functions, so be carefull...

Serge
What is the scope of the DO EVENTS command?
In other words, what functions can it affect?
I get by with a little help from my friends
User avatar
serge_girard
Posts: 3161
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 »

All functions CAN affect. See this sample :

Code: Select all

#include "hmg.ch"


lPAUSE := .f.

aDBF := {}
AADD(aDBF, { "T1", "C", 8, 0 })
AADD(aDBF, { "T2", "C", 8, 0 })
DBCREATE("TEST", aDBF)

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

   @ 120,200 BUTTON START2 ;
      CAPTION 'Interfere loop' ;
      WIDTH 80 ;
      HEIGHT 30 ;
      ACTION Interfere();
      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

USE  TEST 


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

   DO EVENTS
   IF lPAUSE
      lPAUSE := .F.
      npos += 1
      APPEND BLANK
      REPLACE T1 WITH ALLTRIM(STR(x1))
      REPLACE T2 WITH ALLTRIM(STR(y1))
      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

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



FUNCTION Interfere()
/*******************/
x1    := 1
y1    := 2
npos  := 0
USE  TEST 
ZAP
CLOSE ALL
Press: Start loop then Pause then Interfere and finally again Pause.
Interfere has closed DBF which is used in JLOOP.

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_girard wrote: Mon Aug 21, 2017 4:23 pm Press: Start loop then Pause then Interfere and finally again Pause.
Interfere has closed DBF which is used in JLOOP.

Serge
Yes, but if you do not press the button "Interfere", they will not close, right?

My question is oriented to which events are activated. Only those of the window "mathematica" or others besides?
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 »

serge_girard wrote: Mon Aug 21, 2017 4:23 pm All functions CAN affect. See this sample :

Code: Select all

#include "hmg.ch"


lPAUSE := .f.

aDBF := {}
AADD(aDBF, { "T1", "C", 8, 0 })
AADD(aDBF, { "T2", "C", 8, 0 })
DBCREATE("TEST", aDBF)

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

   @ 120,200 BUTTON START2 ;
      CAPTION 'Interfere loop' ;
      WIDTH 80 ;
      HEIGHT 30 ;
      ACTION Interfere();
      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

USE  TEST 


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

   DO EVENTS
   IF lPAUSE
      lPAUSE := .F.
      npos += 1
      APPEND BLANK
      REPLACE T1 WITH ALLTRIM(STR(x1))
      REPLACE T2 WITH ALLTRIM(STR(y1))
      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

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



FUNCTION Interfere()
/*******************/
x1    := 1
y1    := 2
npos  := 0
USE  TEST 
ZAP
CLOSE ALL
Press: Start loop then Pause then Interfere and finally again Pause.
Interfere has closed DBF which is used in JLOOP.

Serge
Your example is very close to what I need, but it would be the inverse of what I need not to loop, but to advance once each time I need a button without a loop.
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: Thu Aug 24, 2017 10:42 pm Your example is very close to what I need, but it would be the inverse of what I need not to loop, but to advance once each time I need a button without a loop.
Explique isso em português --[o en español si fuese posible]--.

Mas, no caso, tente não colocar lpause:=.F.

Sempre lpause:=.T. invariavelmente, colocá-lo no início e não mudá-lo.

Veja se isso funciona da maneira que você deseja, ou algo ainda mais parecido.
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: Fri Aug 25, 2017 6:36 am
jairpinho wrote: Thu Aug 24, 2017 10:42 pm Your example is very close to what I need, but it would be the inverse of what I need not to loop, but to advance once each time I need a button without a loop.
Explique isso em português --[o en español si fuese posible]--.

Mas, no caso, tente não colocar lpause:=.F.

Sempre lpause:=.T. invariavelmente, colocá-lo no início e não mudá-lo.

Veja se isso funciona da maneira que você deseja, ou algo ainda mais parecido.
ola Beges, eu preciso fazer um for ou while com loop manual por um botão somente pode avançar quando eu apertar o botão, hoje o for e o while ficam em automático fazendo este loop.
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: Fri Aug 25, 2017 4:43 pm ola Beges, eu preciso fazer um for ou while com loop manual por um botão somente pode avançar quando eu apertar o botão, hoje o for e o while ficam em automático fazendo este loop.
Ok.
No modo console eu poderia ajudar, mas no modo gráfico não posso... Comecei neste verão e não poderia dedicar muito tempo. :oops:
Mas vou explicar de outra maneira e talvez seja assim que nossos amigos podem ajudar. ;)
I get by with a little help from my friends
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 think I know what Jairpinho wants. Here is an example.
Two buttons are required: START and CONTINUE.
The START button is pressed and the loop starts:

----------------------------------

A:=0

WHILE A<9

A +=1

>>> Suspend the process waiting for the CONTINUE button to be pressed <<<

END

---------------------------------

No inner messages. (You might also want to have a CANCEL button).
I get by with a little help from my friends
Post Reply