Sign in to follow this  
Followers 0
hl1202

Stop the function?

2 posts in this topic

Hi guys, i'm new to AutoIt. I'm trying to write a program with 2 button: 1 start and one stop.

I have a parameter $i = 0. If i > -1 then the Start function will repeat again and again. If i = -1 then it should stop.

My start function worked perfectly. However, i couldn't make it stop.

Here my code

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode",1)
GUICreate("Test", 100, 100)
$startButton = GUICtrlCreateButton("Start", 30,30)
GUICtrlSetOnEvent($startButton,"StartClick")
GUISetState(@SW_SHOW)
$stopButton = GUICtrlCreateButton("Stop", 30,60)
GUICtrlSetOnEvent($stopButton,"StopClick")


GUISetOnEvent($GUI_EVENT_CLOSE,"CloseClick")
Global $i = 0

While 1
    Sleep(1000)
WEnd

Func StopClick()
    $i=-1
    MsgBox(0, "", "Do you want to stop?")
EndFunc

Func CloseClick()
    Exit
EndFunc 

Func StartClick()
$title = WinGetHandle("Notepad","") 

while $i <> -1
    
    WinActivate($title,"")
    ControlSend($title,"","","{ENTER}")
    
    ControlSend($title,"","","Test")
    
    ControlSend($title,"","","{ENTER}")  
    Sleep(5000)
WEnd    
EndFunc

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  
Followers 0