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

edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

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

Post by edk »

Maybe something like this:?

Code: Select all

#include <hmg.ch>

Function Main
nStatus:=0
DEFINE WINDOW main AT 138 , 235 WIDTH 519 HEIGHT 129 VIRTUAL WIDTH Nil VIRTUAL HEIGHT Nil TITLE "" ICON NIL MAIN CURSOR NIL ON INIT Nil ON RELEASE Nil ON INTERACTIVECLOSE Nil ON MOUSECLICK Nil ON MOUSEDRAG Nil ON MOUSEMOVE Nil ON SIZE Nil ON MAXIMIZE Nil ON MINIMIZE Nil ON PAINT Nil BACKCOLOR Nil NOTIFYICON NIL NOTIFYTOOLTIP NIL ON NOTIFYCLICK Nil ON GOTFOCUS Nil ON LOSTFOCUS Nil ON SCROLLUP Nil ON SCROLLDOWN Nil ON SCROLLLEFT Nil ON SCROLLRIGHT Nil ON HSCROLLBOX Nil ON VSCROLLBOX Nil

    DEFINE BUTTON Button_1
        ROW    30
        COL    40
        WIDTH  100
        HEIGHT 28
        ACTION main_button_1_action()
        CAPTION "Start Loop"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

    DEFINE BUTTON Button_2
        ROW    30
        COL    180
        WIDTH  150
        HEIGHT 30
        ACTION nStatus:=2
        CAPTION "Continue Loop"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

    DEFINE BUTTON Button_3
        ROW    30
        COL    360
        WIDTH  100
        HEIGHT 28
        ACTION nStatus:=3
        CAPTION "Abort Loop"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

END WINDOW



main.button_1.enabled:=.T.
main.button_2.enabled:=.F.
main.button_3.enabled:=.F.
        Main.Center
        Main.Activate

Return

Function main_button_1_action

Local nMax:=9, n:=0

//nStatus=1 running
//nStatus=2 continue
//nStatus=3 Abort

main.button_1.enabled:=.F.

 
DO While n<nMax .AND. nStatus#3

nStatus:=1	
n++

main.button_2.Caption:="Continue Loop ("+Ltrim(hb_ValTOStr(n))+" of "+LTrim(hb_ValTOStr(nMax))+")"
main.button_2.enabled:=.T.
main.button_3.enabled:=.T.
DO While nStatus=1
	DO events
	hb_releaseCPU()
EndDo
main.button_2.enabled:=.F.
main.button_3.enabled:=.F.

Enddo

main.button_1.enabled:=.T.
main.button_2.Caption:="Continue Loop"

nStatus:=0
Return Nil

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 »

Perfect, edk. ;)

At least that's the idea I got.

I trust that it will serve to Jairpinho.

P.S.: It is very curious the function hb_releaseCPU() :geek:
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 »

edk wrote: Fri Aug 25, 2017 10:38 pm Maybe something like this:?

Code: Select all

#include <hmg.ch>

Function Main
nStatus:=0
DEFINE WINDOW main AT 138 , 235 WIDTH 519 HEIGHT 129 VIRTUAL WIDTH Nil VIRTUAL HEIGHT Nil TITLE "" ICON NIL MAIN CURSOR NIL ON INIT Nil ON RELEASE Nil ON INTERACTIVECLOSE Nil ON MOUSECLICK Nil ON MOUSEDRAG Nil ON MOUSEMOVE Nil ON SIZE Nil ON MAXIMIZE Nil ON MINIMIZE Nil ON PAINT Nil BACKCOLOR Nil NOTIFYICON NIL NOTIFYTOOLTIP NIL ON NOTIFYCLICK Nil ON GOTFOCUS Nil ON LOSTFOCUS Nil ON SCROLLUP Nil ON SCROLLDOWN Nil ON SCROLLLEFT Nil ON SCROLLRIGHT Nil ON HSCROLLBOX Nil ON VSCROLLBOX Nil

    DEFINE BUTTON Button_1
        ROW    30
        COL    40
        WIDTH  100
        HEIGHT 28
        ACTION main_button_1_action()
        CAPTION "Start Loop"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

    DEFINE BUTTON Button_2
        ROW    30
        COL    180
        WIDTH  150
        HEIGHT 30
        ACTION nStatus:=2
        CAPTION "Continue Loop"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

    DEFINE BUTTON Button_3
        ROW    30
        COL    360
        WIDTH  100
        HEIGHT 28
        ACTION nStatus:=3
        CAPTION "Abort Loop"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

END WINDOW



main.button_1.enabled:=.T.
main.button_2.enabled:=.F.
main.button_3.enabled:=.F.
        Main.Center
        Main.Activate

Return

Function main_button_1_action

Local nMax:=9, n:=0

//nStatus=1 running
//nStatus=2 continue
//nStatus=3 Abort

main.button_1.enabled:=.F.

 
DO While n<nMax .AND. nStatus#3

nStatus:=1	
n++

main.button_2.Caption:="Continue Loop ("+Ltrim(hb_ValTOStr(n))+" of "+LTrim(hb_ValTOStr(nMax))+")"
main.button_2.enabled:=.T.
main.button_3.enabled:=.T.
DO While nStatus=1
	DO events
	hb_releaseCPU()
EndDo
main.button_2.enabled:=.F.
main.button_3.enabled:=.F.

Enddo

main.button_1.enabled:=.T.
main.button_2.Caption:="Continue Loop"

nStatus:=0
Return Nil



thank you edk worked perfect, exactly as i needed
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
Post Reply