Jump to content

[SOLVED] Start Stop Function


Recommended Posts

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

Global $i = 0
Global $kBoolean = True


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 272, 234, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 16, 16, 225, 161)
GUICtrlSetData(-1, "Edit1")
$Button1 = GUICtrlCreateButton("start", 40, 184, 75, 25)
$Button2 = GUICtrlCreateButton("stop", 168, 184, 75, 25)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Func line()

                While $kBoolean
                    GUICtrlSetData($Edit1,"line : "&$i&@CRLF,1)
                    Sleep(1000)
                    $i += 1
                WEnd
EndFunc


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            line()

        Case $Button2
            
            $kBoolean = False



    EndSwitch
WEnd

I have two button ( "start" and "stop") .

When I click start it will print "line :" $i += 1 .

but when I want to stop and resume after stopped.

What should I write to do "that" function I want.

sorry for my bad english.

Thanks for reading

Edited by ImStUPid
Link to comment
Share on other sites

It doesn't work because you are trapped in the While loop inside the function
You might use OnEvent mode, or simpler way use AdlibRegister (example below)
The $i  variable can be declared as Global at the top of the script or as Static inside the function line()

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

; Global $i = 0

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 272, 234, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 16, 16, 225, 161)
GUICtrlSetData(-1, "Edit1")
$Button1 = GUICtrlCreateButton("start", 40, 184, 75, 25)
$Button2 = GUICtrlCreateButton("stop", 168, 184, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            line()
            AdlibRegister(line, 1000)

        Case $Button2          
             AdlibUnRegister(line)

    EndSwitch
WEnd

Func line()
       Local Static $i = 0
       GUICtrlSetData($Edit1,"line : "&$i&@CRLF,1)
       $i += 1
EndFunc

 

Link to comment
Share on other sites

2 hours ago, mikell said:

It doesn't work because you are trapped in the While loop inside the function
You might use OnEvent mode, or simpler way use AdlibRegister (example below)
The $i  variable can be declared as Global at the top of the script or as Static inside the function line()

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

; Global $i = 0

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 272, 234, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 16, 16, 225, 161)
GUICtrlSetData(-1, "Edit1")
$Button1 = GUICtrlCreateButton("start", 40, 184, 75, 25)
$Button2 = GUICtrlCreateButton("stop", 168, 184, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            line()
            AdlibRegister(line, 1000)

        Case $Button2          
             AdlibUnRegister(line)

    EndSwitch
WEnd

Func line()
       Local Static $i = 0
       GUICtrlSetData($Edit1,"line : "&$i&@CRLF,1)
       $i += 1
EndFunc

 

Appreciate your help

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...