Jump to content

Issue Automize Tasks with GUI Function Close after finish


Recommended Posts

Hello nice to meet you,
 
my name is Tobias. Iam new to autoit and working now since 4 weeks on my little tool that should help me to automate 
my daily business work.
 
Iam working at data analyse and wish to automize some daily tasks for me. 
Unfortunately, the software that i need to use at my work is only remoted displayed. 

So iam unable to use any button classes or something like that so trigger the buttons. 
I have invested 2 weeks for imagesearch function (its working now very well).
 
Basicly i have createt a GUI with tabs which include some nessesary settings. 
I want to automize some really basic stuff..
 
Now i stuck with some steps with the script, i need your help and i hope you can help me out..
 
1. The script wont stop when pressing "stop" 
-> the main script always run and run, wont stop when pressing "stop" button - is there a way to stop it 
immediately or any other workaround? 
2. the while loop at main function dont work 
-> after the called function is function is finished it stops and close my GUI - WHY?
 
 
I hope you can help me out!
 
here is the basic code..
 
#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <Date.au3>
#include "_ImageSearch.au3"
#include "_ImageSearch_Debug.au3"
#include <WinAPI.au3>



;arrays
Global $WHATTODO[2] = ["Excel Convert", "BL Daily Analyse"]


$sList = ""
For $i = 0 To UBound($WHATTODO) - 1
    $sList &= "|" & $WHATTODO[$i]
 Next


#Region ### START Koda GUI section ### Form=c:\users\tobias\desktop\bot\gui\form3_1.kxf
$Form1_1 = GUICreate("Dailys Tasks Automize", 401, 601, 290, 220)
GUISetBkColor(0xE3E3E3)
$Button1 = GUICtrlCreateButton("Run", 64, 512, 121, 41)
$Button2 = GUICtrlCreateButton("Stop", 211, 512, 121, 41)
$Log=GUICtrlCreateEdit("", 64, 360, 265, 129, BitOR($ES_AUTOVSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL))
$Tab1 = GUICtrlCreateTab(0, 0, 393, 337)
$TabSheet1 = GUICtrlCreateTabItem("Main")

$Label2 = GUICtrlCreateLabel("SELECT WHAT TO DO", 139, 132, 114, 17)
$Combo1_GM = GUICtrlCreateCombo("Combo1", 104, 160, 185, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData($Combo1_GM, $sList) ;weiße dropdown die werte zu
$Combo2 = GUICtrlCreateCombo("Combo1", 108, 89, 185, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))



GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
GUICtrlSetState($Button2,$GUI_DISABLE)
GUICtrlSetState($Button1,$GUI_ENABLE)
#AutoIt3Wrapper_Compile_Both=y  ;ist notwendig
#AutoIt3Wrapper_UseX64=y  ;ist notwendig
#EndRegion ### END Koda GUI section ###








$sOSArch = @OSArch ;Check if running on x64 or x32 Windows ;@OSArch Returns one of the following: "X86", "IA64", "X64" - this is the architecture type of the currently running operating system.
ConsoleWrite("$sOSArch=" & $sOSArch & @CR)
$sAutoItX64 = @AutoItX64 ;Check if using x64 AutoIt ;@AutoItX64 Returns 1 if the script is running under the native x64 version of AutoIt.
ConsoleWrite("$sAutoItX64=" & $sAutoItX64 & @CR)





Global $window = WinGetHandle("Data Analyse LVS Logistic") ;activate program window
;Global $running = false
Global $runner
$runner = false
If Not IsDeclared($runner) Then Global $runner



While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            GUISwitch($Form1_1);wechsel zum GUI
            GUIDelete()
            Exit
         Case $msg = $Button1;start
            GUICtrlSetState($Button1,$GUI_DISABLE)
            GUICtrlSetState($Button2,$GUI_ENABLE)
            sleep(100)
            $runner = true
            sleep(100)
            StartStop();start function startup

        Case $msg = $Button2;stop
           GUICtrlSetState($Button2,$GUI_DISABLE)
            GUICtrlSetState($Button1,$GUI_ENABLE)
            sleep(100)
            $runner = False
            sleep(100)
            StartStop()
    EndSelect
WEnd






Func StartStop()
    If ($runner = true) Then
        sleep(200)
        startup()
    Else
        $runner = False
        sleep(200)
        _WriteLineToLog("Stop Analysis after this task..")
    EndIf
EndFunc



Func _WriteLineToLog($Log_String_WriteLineToLog)
    GUICtrlSetData($Log, _NowCalc() & " - " & $Log_String_WriteLineToLog & @CRLF, 1)
Endfunc


;-----------------------------STARTUP----------------------------------------


Func startup()







Opt("PixelCoordMode", 2)
$window = WinGetHandle("Data Analyse LVS Logistic")

$login = 0
$loginwhile = 0
$program = "D:\Program Files\Data Logistic\bin\LVS.exe"

If ProcessExists("LVS.exe") Then
_WriteLineToLog("detected running LVS")
sleep(2000)
Else
; starte program
Run($program)
WinWait("Data Analyse LVS Logistic")
sleep(5000)
EndIf

excelconvert()




EndFunc


;----------------------------START AUTOMIZE TASK

Func excelconvert()

Opt("PixelCoordMode", 2)
$window = WinGetHandle("Data Analyse LVS Logistic")



   $Running = 0
    While $Running = 0

;do tasks...

;if task finished $Running =+1 ......

WEnd

EndFunc



Func analysedata()

   $Running = 0
    While $Running = 0

;do tasks...

;if task finished $Running =+1 ......


EndFunc


Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

Link to post
Share on other sites

It is normal since the script is caught in a while..wend loop.  Pressing a GUI button won't interrupt the processing unless you change the GUI into Opt("GUIOnEventMode", 1). 

Link to post
Share on other sites

Hello Nine, thank you for reply. 

 

I have already tryed it.

 

For example, here it work perfect, the script stop when pressing stop button:

 

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

Opt("GUIOnEventMode",1)

Global $Stop = True
Global $x = 1, $i = 0

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 579, 212, 192, 124)
Global $Button1 = GUICtrlCreateButton("Stop", 432, 136, 75, 25)
Global $Button2 = GUICtrlCreateButton("Start", 96, 136, 75, 25)
Global $Progress1 = GUICtrlCreateProgress(24, 40, 526, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent ($GUI_EVENT_CLOSE, "_exit",$Form1 )
GUICtrlSetOnEvent($Button2,"_Start")
GUICtrlSetOnEvent($Button1,"_Stop")

While 1
    While $Stop = False
        $i += $X
        GUICtrlSetData($Progress1,$i)
        Sleep(80)
        if $i = 105 Then $X = -1
        if $i = 0 Then $X =  1
    WEnd
    Sleep(80)
WEnd

Func _Stop ()
    $Stop = True
EndFunc

Func _exit ()
    Exit
EndFunc

Func _Start ()
    $Stop = False
EndFunc

But my version wont stop, i start a function on start button:

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

Opt("GUIOnEventMode",1)

Global $Stop = True
Global $x = 1, $i = 0

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 579, 212, 192, 124)
Global $Button1 = GUICtrlCreateButton("Stop", 432, 136, 75, 25)
Global $Button2 = GUICtrlCreateButton("Start", 96, 136, 75, 25)
Global $Progress1 = GUICtrlCreateProgress(24, 40, 526, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent ($GUI_EVENT_CLOSE, "_exit",$Form1 )
GUICtrlSetOnEvent($Button2,"_Start")
GUICtrlSetOnEvent($Button1,"_Stop")

While 1
WEnd

func test()
    While $Stop = False
        $i += $X
        GUICtrlSetData($Progress1,$i)
        Sleep(80)
        if $i = 105 Then $X = -1
        if $i = 0 Then $X =  1
    WEnd
    
endfunc

Func _Stop ()
    $Stop = True
EndFunc

Func _exit ()
    Exit
EndFunc

Func _Start ()
    $Stop = False
    test()
EndFunc

Can you please explain me why it doesnt work, using a function?

Edited by Tobias092
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...