Jump to content

Recommended Posts

Posted

Hello everyone,

Have a tricky question:
 
How i manage to exit from loop, but not from script?
(ExitLoop it is ok, but runned out of ways, how to use it in my script :( )
 
With this i have a problem:
If i unpause (F2) the script, it will continue the loop.
While scrip is paused (F2) i can restart it (F1), but:
While script is paused (F2), and i open  my form (F3), and try to press button on it, it will not work, cause active loop is paused at background. (I hope i understand right the method)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{F1}", "RunScript")
HotKeySet("{F2}", "Pause")
HotKeySet("{F3}", "OpenForm")

Global $Pause

$GUI_Create_Form = GUICreate("Settings", 175, 95)
$Button_Save = GUICtrlCreateButton("Save", 10, 60, 75, 25)
$Button_Cancel = GUICtrlCreateButton("Cancel", 90, 60, 75, 25)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button_Save
            MsgBox(0, "Notification", "Settings have been saved!", 1)
            GUISetState(@SW_HIDE)
        Case $Button_Cancel
            GUISetState(@SW_HIDE)
    EndSwitch
WEnd

Func RunScript()
    Local $Numbers = 1
    While 1
        $Numbers = $Numbers + 1
        Sleep(250)
        ToolTip("Numbers:" & $Numbers, 0, 0)
    WEnd
EndFunc   ;==>RunScript

Func Pause()
    $Pause = Not $Pause
    While $Pause
        Sleep(100)
        ToolTip('Scrpit is "Paused"', 0, 0)
    WEnd
    ToolTip("", 0, 0)
EndFunc   ;==>Pause

Func OpenForm()
    GUISetState()
EndFunc   ;==>OpenForm

All i want is, brake the counter loop with hotkey.
Can anyone help me to give a logical answare?
(I do need the form with buttons, to store data / save settings)

Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

Posted

Hi. You can Use AdlibRegister.

Something like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{F1}", "Start")
HotKeySet("{F2}", "Pause")
HotKeySet("{F3}", "OpenForm")

Global $Pause=False

$GUI_Create_Form = GUICreate("Settings", 175, 95)
$Button_Save = GUICtrlCreateButton("Save", 10, 60, 75, 25)
$Button_Cancel = GUICtrlCreateButton("Cancel", 90, 60, 75, 25)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button_Save
            MsgBox(0, "Notification", "Settings have been saved!", 1)
            GUISetState(@SW_HIDE)
        Case $Button_Cancel
            GUISetState(@SW_HIDE)
    EndSwitch
WEnd



Func RunScript()
Local Static $Numbers = 1
ToolTip("Numbers:" & $Numbers, 0, 0)
$Numbers+=1
EndFunc   ;==>RunScript


Func Start()
    If not $Pause then
    AdlibRegister("RunScript")
    $Pause=True
    EndIf
EndFunc


Func Pause()
    AdlibUnRegister("RunScript")
    $Pause=False
EndFunc


Func OpenForm()
    GUISetState()
EndFunc   ;==>OpenForm

Saludos

  • Solution
Posted

Well You real question was another. to break the loop You can do this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{F1}", "RunScript")
HotKeySet("{F2}", "Pause")
HotKeySet("{F3}", "OpenForm")

Global $Pause=False

$GUI_Create_Form = GUICreate("Settings", 175, 95)
$Button_Save = GUICtrlCreateButton("Save", 10, 60, 75, 25)
$Button_Cancel = GUICtrlCreateButton("Cancel", 90, 60, 75, 25)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button_Save
            MsgBox(0, "Notification", "Settings have been saved!", 1)
            GUISetState(@SW_HIDE)
        Case $Button_Cancel
            GUISetState(@SW_HIDE)
    EndSwitch
WEnd

Func RunScript()
    Local $Numbers = 1
    $Pause=False
    While 1
        $Numbers = $Numbers + 1
        Sleep(250)
        ToolTip("Numbers:" & $Numbers, 0, 0)
        if $Pause=True Then
        ToolTip('Scrpit is "Paused"', 0, 0)
         ExitLoop
        EndIf
    WEnd
EndFunc   ;==>RunScript

Func Pause()
 $Pause=True
EndFunc   ;==>Pause

Func OpenForm()
    GUISetState()
EndFunc   ;==>OpenForm

Sorry for my caveman english :S

Saludos

Posted (edited)

I change Pause function as Stop and I added a pause function what only pause the script. So now work fine.

I am able to:

  • Run script
  • Pause script
  • Exit from loop
  • Restart / continue the script

 

Did not know u can use True / False on pause function like this. More simple then Help file examples.

Ps.: Your english is good enough. So do not worry about it. ;)

Thank you!

Tricky

Edited by TrickyDeath

Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

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
×
×
  • Create New...