Hi I am new to autoit and have spent maybe a week scripting.
I found some code that creates a gui and adds buttons for start and stop.
It's using a switch or interrupt to swtich between two functions. One functions runs my main progroam (func1) the other just idles and intterupts the first program and stops it from continuing further (func2). When i first run the script the gui comes up and i can lcick start and the first function runs as it should. I click stop and the first function halts (and hte second function starts which is to idle). Now if i click start again it wont run the first function, i have to click start twice after stopping to get the main function to run. Any help would be appreciated. I've ommited some stuff for the main func that shouldnt matter.
I found some code that creates a gui and adds buttons for start and stop.
It's using a switch or interrupt to swtich between two functions. One functions runs my main progroam (func1) the other just idles and intterupts the first program and stops it from continuing further (func2). When i first run the script the gui comes up and i can lcick start and the first function runs as it should. I click stop and the first function halts (and hte second function starts which is to idle). Now if i click start again it wont run the first function, i have to click start twice after stopping to get the main function to run. Any help would be appreciated. I've ommited some stuff for the main func that shouldnt matter.
[ autoit ]
#include #include ; Declare a flag $fInterrupt = 0 Opt("GUIOnEventMode", 1) Opt('MouseCoordMode', 0) $hGUI = GUICreate("Trading Script", 200, 100) GUISetBkColor (0xff3300) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $hButton_1 = GUICtrlCreateButton("Start", 15, 10, 80, 30) GUICtrlSetOnEvent($hButton_1, "_Func_1") $hButton_2 = GUICtrlCreateButton("Stop", 100, 10, 80, 30) GUICtrlSetOnEvent($hButton_2, "_Func_2") $hButton_3 = GUICtrlCreateButton("Run", 40, 50, 125, 30) GUICtrlSetOnEvent($hButton_3, "_Func_3") GUISetState() ; Intercept Windows command messages with out own handler GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 sleep(10) WEnd Func _Func_1() ;FUNCTION START ; Make sure the flag is cleared $fInterrupt = 0 $runner = Not $runner While $runner GUISetBkColor (0x33ff33) Local $getfile = 0 While $getfile = 0 ;Interrupt switch If $fInterrupt <> 0 Then ; The flag was set Switch $fInterrupt Case 1 ConsoleWrite("SCRIPT HALTED" & @CRLF) EndSwitch Return EndIf ;Interrupt switch If FileExists("C.txt") Then $file = FileOpen("C.txt", 0) $All = FileReadLine($file, -1) $Upper = StringMid($All, 7, 6) $Lower = StringMid($All, 20, 6) $Last = StringMid($All, 33, 6) $getfile = 1 Else ConsoleWrite("No File" & @CRLF) $getfile = 0 sleep(1250) EndIf WEnd EndFunc Func _Func_2() GUISetBkColor (0xff3300) Sleep(100) EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ; The Func 2 button was pressed so set the flag If BitAND($wParam, 0x0000FFFF) = $hButton_2 Then $fInterrupt = 1 Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND