Jump to content
Sign in to follow this  
Reinhardt1julian

AutoIt Loops Start + Stop

Recommended Posts

Reinhardt1julian

Hi, I'm new. I want to make a GUI with 3 Buttons. The first button is "start" and starts an infinite loop. The second is "stop" and stops the loop. The third should be "exit" and closes the window. What is the code i need for that?

Share this post


Link to post
Share on other sites
Shaggi

Normally, you already have an infinite loop that either keeps your program running or polls the gui for messages... But this could be an example:

#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.7.18 (beta)
Author:      myName
Script Function:
    Template AutoIt script.
#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Global $gInfiniteLoop = false
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 262, 125, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$Button1 = GUICtrlCreateButton("Start", 8, 8, 81, 25)
GUICtrlSetOnEvent(-1, "StartClick")
$Button2 = GUICtrlCreateButton("Stop", 8, 40, 81, 25)
GUICtrlSetOnEvent(-1, "StopClick")
$Button3 = GUICtrlCreateButton("Exit", 8, 72, 81, 25)
GUICtrlSetOnEvent(-1, "ExitClick")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While Sleep(10)
    If $gInfiniteLoop Then ; Bit redundant
        While $gInfiniteLoop
            #cs
                Infinite Loop
            #ce
        WEnd
    EndIf
    #cs
        Other code?
    #ce
WEnd
Func StartClick()
    $gInfiniteLoop = true
EndFunc
Func StopClick()
    $gInfiniteLoop = False
EndFunc
Func ExitClick()
    Exit
EndFunc
Func Form1Close()
    Exit
EndFunc
Func Form1Maximize()
EndFunc
Func Form1Minimize()
EndFunc
Func Form1Restore()
EndFunc

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Share this post


Link to post
Share on other sites
martin

Welcome to the forums Reinhardt1julian :oops:.

Your requirements are all very sensible, but the expectation that someone supply the code is optimistic, and in any case, it would not be the best way to learn. The first thing to do is spend a lot of time reading the help file and playing with the examples. The help is very good and the examples will get you where you want to go although understanding them might be hard at first if you are a raw beginner.Then try to get somewhere with just making a button do something, and when you have a problem post your code no matter how good or bad you think it is and ask for help. You will get lots of help that way and you will learn faster in the end.

This link might be helpful.

Of course later posts might contain very different responses.

Edit: Of course earlier posts might contain very different responses.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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  

×