Jump to content

Trouble stopping Function


Recommended Posts

Hi all,

This is my first script!!

I'm trying to stop the function "autophoto" by pressing the stop button, but the script may not close.

So far I've tried several things but without a good result!!

Can somebody please help me?

Thanks

CODE

#include <GuiConstants.au3>

Opt("GUICoordMode", 1)

GuiCreate("Custom", 360, 120)

WinSetOnTop("Custom","",1)

$autophoto = GuiCtrlCreateButton("Auto Photos Start", 10, 10, 100, 40)

$stop = GUICtrlCreateButton("Stop", 10, 60, 100, 40)

$exit = GUICtrlCreateButton("Exit", 250 , 60 , 100 , 40)

GuiSetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()

If $msg = $exit Or $msg = $GUI_EVENT_CLOSE then Exit

Select

Case $msg = $autophoto

autophoto()

EndSelect

WEnd

Func AutoPhoto()

;MsgBox(0, "Remember", "Activate auto save then press OK to start")

Sleep(2000)

For $i = 1 to 5 Step 1

$Step = 1 + $i

PresetMag($Step)

sleep(2000)

Photo()

sleep(500)

Next

EndFunc

Func Photo()

WinActivate("Window")

ControlClick ("Window", "", 66 , "left" , 1 , 20 , 20); collect photo

sleep(90000)

EndFunc

Func PresetMag($Step)

WinActivate("Window")

send("!p")

sleep(1000)

Send("{UP " & $Step &"}")

sleep(1000)

Send("{ENTER}")

EndFunc

Electron microscopes rule!!!
Link to comment
Share on other sites

Classic case for Event Mode:

#include <GuiConstants.au3>

Opt("GuiOnEventMode", 1); Set event mode
Opt("GUICoordMode", 1)

Global $fRun = False

GUICreate("Custom", 360, 120)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$autophoto = GUICtrlCreateButton("Auto Photos Start", 10, 10, 100, 40)
GUICtrlSetOnEvent(-1, "AutoPhoto")
$stop = GUICtrlCreateButton("Stop", 10, 60, 100, 40)
GUICtrlSetOnEvent(-1, "_Stop")
$exit = GUICtrlCreateButton("Exit", 250, 60, 100, 40)
GUICtrlSetOnEvent(-1, "_Quit")

GUISetState(@SW_SHOW)
WinSetOnTop("Custom", "", 1)

While 1
    Sleep(20)
WEnd

Func AutoPhoto()
    $fRun = True
    Sleep(2000)
    For $i = 1 To 5 Step 1
        $Step = 1 + $i
        If Not $fRun Then Return
        PresetMag($Step)
        If Not $fRun Then Return
        Sleep(2000)
        If Not $fRun Then Return
        Photo()
        If Not $fRun Then Return
        Sleep(500)
    Next
    $fRun = False
EndFunc  ;==>AutoPhoto

Func Photo()
    WinActivate("Window")
    ControlClick("Window", "", 66, "left", 1, 20, 20); collect photo
    Local $iTimer = TimerInit()
    Do 
        If Not $fRun Then Return
        Sleep(20)
    Until TimerDiff($iTimer) >= 90000
EndFunc  ;==>Photo

Func PresetMag($Step)
    WinActivate("Window")
    Send("!p")
    Sleep(1000)
    Send("{UP " & $Step & "}")
    Sleep(1000)
    Send("{ENTER}")
EndFunc  ;==>PresetMag

Func _Quit()
    Exit
EndFunc

Func _Stop()
    $fRun = False
EndFunc

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 3 weeks later...

Thanks for your respons PsaltyDS,

It doesn't work, I think the string doesn't change while being in the For Next loop.

Is it possible to show this string in my GUI? If yes how to do it!!

Thanks

Electron microscopes rule!!!
Link to comment
Share on other sites

You must 'listen' for the stop message inside the AutoPhoto function.

Func AutoPhoto()
;MsgBox(0, "Remember", "Activate auto save then press OK to start")
    
;Sleep(2000) I'm replacing this by a timer so I can listen to the stop message
    $timer = TimerInit()
    While TimerDiff($timer) < 2000
        Sleep(10)
        If GUIGetMsg() = $stop Then Return
    WEnd
    
    For $i = 1 to 5 Step 1
        $Step = 1 + $i
        PresetMag($Step)
        
    ;Sleep(2000) I'm replacing this by a timer so I can listen to the stop message
        $timer = TimerInit()
        While TimerDiff($timer) < 2000
            Sleep(10)
            If GUIGetMsg() = $stop Then Return
        WEnd
        
        Photo()
        
    ;Sleep(500) I'm replacing this by a timer so I can listen to the stop message
        $timer = TimerInit()
        While TimerDiff($timer) < 500
            Sleep(10)
            If GUIGetMsg() = $stop Then Return
        WEnd
        
    Next
EndFunc
Edited by TomZ
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...