EKY32 Posted December 27, 2014 Posted December 27, 2014 Hello, how should I stop any code running inside a loop? using the best method. Thanks. expandcollapse popup#include "WinHttp.au3" #include <WindowsConstants.au3> Global $sDomain = "https://website.com" Global $sPage = "page.html" $Form1 = GUICreate("TEST", 328, 178, 192, 124) $Start = GUICtrlCreateButton("Start", 24, 144, 75, 25) $Stop = GUICtrlCreateButton("Stop", 224, 144, 75, 25) $Console = GUICtrlCreateEdit("", 8, 8, 313, 129) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Start $hOpen = _WinHttpOpen() $hConnect = _WinHttpConnect($hOpen, $sDomain) For $i = 1 To 20 $sReturned = _WinHttpSimpleSSLRequest($hConnect, "POST", $sPage, Default) ; Reporting to console GUICtrlSetData($Console, GUICtrlRead($Console & @CRLF)) Next Case $Stop ; Stop the posting process up there ^ EndSwitch WEnd _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) [font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font]
Jfish Posted December 27, 2014 Posted December 27, 2014 "ExitLoop" will break out of a For loop. So you could say something like "If $stoploop=true then exitloop" from within the loop and use a hotkey or something to set it to true. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
EKY32 Posted December 28, 2014 Author Posted December 28, 2014 Thank you, I don't want to use a hotkey, how should I handle the cancel code to pass the ExitLoop command while i'm inside that loop? [font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font]
Moderators SmOke_N Posted December 28, 2014 Moderators Posted December 28, 2014 (edited) You don't want to use a hotkey? Okay, so now the question... "What method would you like to use to tell the script to stop looping?" Edit: P.S. Not sure yelling at it without code to interpret and a mic is going to work. Edited December 28, 2014 by SmOke_N Jfish 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
kylomas Posted December 29, 2014 Posted December 29, 2014 (edited) This stmt results in nothing... GUICtrlSetData($Console, GUICtrlRead($Console & @CRLF)) You probably want... GUICtrlSetData($Console, $sReturned & @CRLF, 1) kylomas edit: To interrupt your loop you might try something like this... expandcollapse popup#include "WinHttp.au3" #include <WindowsConstants.au3> Global $sDomain = "https://website.com" Global $sPage = "page.html" $Form1 = GUICreate("TEST", 600,500) $Start = GUICtrlCreateButton("Start", 10, 450, 100, 20) $Stop = GUICtrlCreateButton("Stop", 150,450,100,20) $Console = GUICtrlCreateEdit("", 10, 10, 580, 400) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit Case $Start $hOpen = _WinHttpOpen() $hConnect = _WinHttpConnect($hOpen, $sDomain) For $i = 1 To 20 if guigetmsg() = $stop then exitloop ; < ------- test for stop control $sReturned = _WinHttpSimpleSSLRequest($hConnect, "POST", $sPage, Default) ; Reporting to console GUICtrlSetData($Console, $sReturned & @CRLF, 1) Next Case $Stop ; Stop the posting process up there ^ EndSwitch WEnd _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Edited December 29, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now