Jump to content
Sign in to follow this  
CHronologist

Stop function with another

Recommended Posts

CHronologist

Basically the code looks like this:

CODE
#include "GUIConstants.au3"

GUICreate("Control", 300, 300)

$exitbtn = GUICtrlCreateButton("Exit", 210, 40, 80, 30)

$downbtn = GUICtrlCreateButton("Download", 10, 40, 80, 30)

Opt("GUIOnEventMode", 1)

GUICtrlSetOnEvent($exitbtn, "_exit")

GUICtrlSetOnEvent($downbtn, "_down")

GUISetState(@SW_SHOW)

Global $loopcode = 1

While 1

;here runs a main routine

WEnd

Func _down()

GUICtrlSetData($exitbtn, "Stop")

While $loopcode = 1

;do something

WEnd

GUICtrlSetData($exitbtn, "Exit")

$loopcode = 1

EndFunc

Func _exit()

If GUICtrlRead($exitbtn) = "Stop" Then

$loopcode = 0

ElseIf GUICtrlRead($exitbtn) = "Exit" Then

Exit

EndIf

EndFunc

I just cut out the important parts. The intention is that while the mainroutine is running the exitbutton should end the programm. If inside the _down function the exitbutton becomes a stopbutton and when this is pressed the variable $loopcode should become 0 so that the While-Loop in the _down function will stop the next time the loop head is tested. For some reason the _exit function is not called. Any suggestions? Thanks for every idea.

Share this post


Link to post
Share on other sites
ProgAndy

You have to make a "Callback". If you donÄt use AdLib, then you can to it like this:

CODE
#include "GUIConstants.au3"

GUICreate("Control", 300, 300)

$exitbtn = GUICtrlCreateButton("Exit", 210, 40, 80, 30)

$downbtn = GUICtrlCreateButton("Download", 10, 40, 80, 30)

Opt("GUIOnEventMode", 1)

GUICtrlSetOnEvent($exitbtn, "_exit")

GUICtrlSetOnEvent($downbtn, "_down")

GUISetState(@SW_SHOW)

Global $loopcode = 0

While 1

;here runs a main routine

WEnd

Func _down()

If Not $loopcode Then

AdlibEnable("_Count")

ConsoleWrite("->Loop started" & @CRLF)

Else

ConsoleWrite("->Loop already running" & @CRLF)

EndIf

EndFunc

Func _exit()

If GUICtrlRead($exitbtn) = "Stop" Then

ConsoleWrite("->Stopping Loop" & @CRLF)

$loopcode = 0

ElseIf GUICtrlRead($exitbtn) = "Exit" Then

Exit

EndIf

EndFunc

Func _Count()

AdlibDisable()

ConsoleWrite("#Count Called" & @CRLF)

GUICtrlSetData($exitbtn, "Stop")

$loopcode = 1

While $loopcode = 1

;do something

ToolTip(@HOUR & ":" & @MIN & ":" & @SEC)

Sleep(10)

WEnd

ToolTip("")

ConsoleWrite("#Count Stopped" & @CRLF)

GUICtrlSetData($exitbtn, "Exit")

EndFunc

Otherwise, you have to use the Timer UDF

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
sandin

try with this:

#include "GUIConstants.au3"
GUICreate("Control", 300, 300)
$exitbtn = GUICtrlCreateButton("Exit", 210, 40, 80, 30)
$downbtn = GUICtrlCreateButton("Download", 10, 40, 80, 30)
Opt("GUIOnEventMode", 1)
GUICtrlSetOnEvent($exitbtn, "_exit")
GUICtrlSetOnEvent($downbtn, "_down")
GUISetOnEvent($GUI_EVENT_CLOSE, "_quit")
$progress = GUICtrlCreateProgress(10, 120, 280)
GUISetState(@SW_SHOW)
Global $loopcode = 0, $over = 0, $i = 0
While 1
    if $loopcode = 1 Then
        if $over = 0 Then
            $i += 1
            Sleep(10)
            GUICtrlSetData($progress, $i)
            if $i = 100 then $over = 1
        Else
            $i -= 1
            Sleep(10)
            GUICtrlSetData($progress, $i)
            if $i = 0 then $over = 0
        EndIf
    EndIf
WEnd
Func _down()
    GUICtrlSetState($downbtn, $GUI_DISABLE)
    $loopcode = 1
    GUICtrlSetData($exitbtn, "Pause")
    GUICtrlSetData($downbtn, "Download")
EndFunc
Func _exit()
    GUICtrlSetState($downbtn, $GUI_ENABLE)
    If GUICtrlRead($exitbtn) = "Pause" Then
        $loopcode = 0
        GUICtrlSetData($exitbtn, "Exit")
        GUICtrlSetData($downbtn, "Continue")
    ElseIf GUICtrlRead($exitbtn) = "Exit" Then
       _quit()
    EndIf
EndFunc
func _quit()
    Exit
EndFunc

Share this post


Link to post
Share on other sites
CHronologist

Ok,works thank you for help.

Edited by CHronologist

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.