itsid Posted April 22, 2018 Share Posted April 22, 2018 Hi, I hope I'm not exactly familiar with AutoIt tbh.. I only use it occasionally for some "sketching" let's say... Anywhoo, I ran into an issue with the GUIMessage... here.. have my loop for a quick view: expandcollapse popup;//runtime variables init local $runmx = -1 local $runit = 1 local $dofetch = False $runmx = grabAllLinks() ;//loop di loop While 1 Local $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $MainGui Switch $aMsg[0] Case $GUI_EVENT_CLOSE ExitScript() Case $men_addsite GuiAddSite() Case $men_addreg GuiAddReg() Case $men_exit ExitScript() Case $btn_startop if $dofetch = true Then $dofetch = false GUICtrlSetData($btn_startop, "Start") Else $dofetch = True GUICtrlSetData($btn_startop, "Pause") EndIf Case Else For $i = 1 To UBound($sites)-1 ;// on the fly created submenu that's why it's an array it loops... If $aMsg[0] = $runsit[$i] Then $runmx = grabLinks($sites[$i][0]) ;rowid $runpname = $sites[$i][1] $dofetch = True GUICtrlSetData($btn_startop, "Pause") elseif $aMsg[0] = $runrefsit[$i] Then local $html = loadPage($sites[$i][2]) ;url $runmx = grabinsertLinks($html, $sites[$i][0]) ;rowid $runpname = $sites[$i][1] $dofetch = True GUICtrlSetData($btn_startop, "Pause") elseif $aMsg[0] = $expsit[$i] Then exportSQL($sites[$i][1]) EndIf Next EndSwitch Case $frmSiteAdd Switch $aMsg[0] Case $GUI_EVENT_CLOSE GUIDelete($frmSiteAdd) Case $btn_add ;//blablabla waaaaay too long GUIDelete($frmSiteAdd) EndSwitch Case $frmRegAdd Switch $aMsg[0] Case $GUI_EVENT_CLOSE GUIDelete($frmRegAdd) Case $btn_add ;//blablabla waaaaay too long GUIDelete($frmRegAdd) EndSwitch EndSwitch ;//the running code is what kinda looses the GUI-message ;//ConsoleWrite($aMsg[0]&", ") simply does NOT write to console once the code below gets triggered if $runit <= $runmx Then if $dofetch = true Then _GUICtrlStatusBar_SetText($StatusBar1, @TAB&@TAB&"page: "&$runit&" of "&$runmx, 2) GUICtrlSetData($total_progress,100*$runit/$runmx) ;// GUI Updates working nicely! ;// so does all other code (reading files, writing to database...everything) ;// except setting $dofetch to false with the GUI button $runit = $runit +1 EndIf EndIf WEnd I'm kinda lost ATM.. occasionally the ConsoleWrite($aMsg[0]) flickers but always a mouse release, never a mouse down (negative values if any) removing the "work" from the While Loop and calling an external function doesn't make it any different, Soooo how can I cache GUIGetMsg(1) in order to trigger or rather UN-trigger the dofetch so the actual workload gets indeed paused? it digs through some thousand files with some hundred loop runs per file, so most of the time it's simply not in said while loop actually, and I just wouldn't want to go through the hassle and requery GUIGetMsg every other line of code just to be sure it triggers my switch... There must be a simpler way of achieving this, no? Do I need a Windows message handle or is there even a simpler way than that... Frankly, personally it's almost quicker for me to get this done in c++... but I kinda like the AutoIt idea and I'd like to use it for sketches like these before I care about error handling or system architecture and all the boring stuff thank you for your help 'sid Link to comment Share on other sites More sharing options...
itsid Posted April 22, 2018 Author Share Posted April 22, 2018 alright alright.. windows message handle it is.... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 22, 2018 Moderators Share Posted April 22, 2018 itsid, Welcome to the AutoIt forums. In future, you might like to consider posting runnable code - lots of people will not take the trouble to add the necessary additional code to get snippets running. Anyway, I did - and your loop seems to work just fine for me (with a small change to the ConsoleWrite line to prevent it going mad and printing for every pass): expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> ;//runtime variables init Local $runmx = -1 Local $runit = 1 Local $dofetch = False $runmx = 2000 Global $sites[2] $MainGui = GUICreate("main", 200, 200, 100, 100) $btn_startop = GUICtrlCreateButton("Test", 10, 10, 80, 30) $total_progress = GUICtrlCreateProgress(10, 90, 180, 20) $men_exit = GUICtrlCreateButton("Exit", 110, 160, 80, 30) $cTest_1 = GUICtrlCreateDummy() $cTest_2 = GUICtrlCreateDummy() $cTest_3 = GUICtrlCreateDummy() GUISetState() $frmSiteAdd = GUICreate("SiteAdd", 200, 200, 400, 100) $btn_add_Site = GUICtrlCreateButton("Add", 10, 10, 80, 30) GUISetState() $frmRegAdd = GUICreate("RegAdd", 200, 200, 700, 100) $btn_add_Reg = GUICtrlCreateButton("Add", 10, 10, 80, 30) GUISetState() ;//loop di loop While 1 Local $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $MainGui Switch $aMsg[0] Case $GUI_EVENT_CLOSE, $men_exit Exit ; ExitScript() ;Case $men_addsite ;GuiAddSite() ;Case $men_addreg ;GuiAddReg() ;Case $men_exit ; ExitScript() Case $btn_startop If $dofetch = True Then $dofetch = False GUICtrlSetData($btn_startop, "Start") Else $dofetch = True GUICtrlSetData($btn_startop, "Pause") EndIf Case Else For $i = 1 To UBound($sites) - 1 ;// on the fly created submenu that's why it's an array it loops... If $aMsg[0] = $cTest_1 Then ;$runsit[$i] Then $runmx = 2000 ;$runpname = $sites[$i][1] $dofetch = True GUICtrlSetData($btn_startop, "Pause") ElseIf $aMsg[0] = $cTest_2 Then ; $runrefsit[$i] Then ;Local $html = loadPage($sites[$i][2]) ;url $runmx = 2000 ;$runpname = $sites[$i][1] $dofetch = True GUICtrlSetData($btn_startop, "Pause") ElseIf $aMsg[0] = $cTest_3 Then ; $expsit[$i] Then ;exportSQL($sites[$i][1]) EndIf Next EndSwitch Case $frmSiteAdd Switch $aMsg[0] Case $GUI_EVENT_CLOSE GUIDelete($frmSiteAdd) Case $btn_add_Site ;//blablabla waaaaay too long GUIDelete($frmSiteAdd) EndSwitch Case $frmRegAdd Switch $aMsg[0] Case $GUI_EVENT_CLOSE GUIDelete($frmRegAdd) Case $btn_add_Reg ;//blablabla waaaaay too long GUIDelete($frmRegAdd) EndSwitch EndSwitch ;//the running code is what kinda looses the GUI-message If $aMsg[0] <> 0 Then ConsoleWrite($aMsg[0] & @CRLF) ; simply does NOT write to console once the code below gets triggered EndIf If $runit <= $runmx Then If $dofetch = True Then ;_GUICtrlStatusBar_SetText($StatusBar1, @TAB & @TAB & "page: " & $runit & " of " & $runmx, 2) GUICtrlSetData($total_progress, 100 * $runit / $runmx) ;// GUI Updates working nicely! ;// so does all other code (reading files, writing to database...everything) ;// except setting $dofetch to false with the GUI button $runit = $runit + 1 EndIf EndIf WEnd So I would suggest that the problem lies elsewhere in your script - of which there is obviously a lot more. M23 itsid 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
itsid Posted April 23, 2018 Author Share Posted April 23, 2018 Hi thank you.. also for trying! that's the issue.. the code itself as I mentioned is quite long and depending on various conditions is getting rather complex quickly.. a single loop (that's called one after another after the switch-cases) can take several seconds loading a file if possible from the HDD, if not from the internet, checking it against a regular expression, and comparing the results against a database, updating the database and/or the GUI according to that, marking the read file as read in the database... aaaand so on and so forth. and worse the code spreads over several files since I like to keep mainloops away from Database or GUI stuff local file access away from remote file access and so forth so that I can replace either more conveniently by just including some other script swapping back if needed As I said it's a sketch, (no error handling, GUI is subpar, cluttered with data in memory, full with dummy functions and unnecessary includes at times etc..) I wouldn't want to bother someone with digging through such mess that's why I didn't post any of my running code (but you are right.. I should have at least fabricobbled some testscript like yours... my apologies) Anyways, a short test like yours works fine for me as well.. that's why I was baffled seeing it fail with longer running tasks; and if I'd put a sleep(2000) in (the dofetch condition) to emulate that longer running task your testscript fails on me as well Just didn't thought of that before I'm afraid Nevermind, I added a windows message handle to resolve that... just removed the case for the start/stop button from the switch and it works fine now... (or say good enough for what I was after here) 'sid Link to comment Share on other sites More sharing options...
Zedna Posted April 23, 2018 Share Posted April 23, 2018 (edited) It's quite important to test result of GUIGetMessage() to nonzero when you use Case Else + For/Next in your GUI loop like this: Note: I shortened your code only to related parts expandcollapse popup;//loop di loop While 1 Local $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $MainGui Switch $aMsg[0] Case $GUI_EVENT_CLOSE ExitScript() Case $men_addsite GuiAddSite() Case Else If $aMsg[0] <> 0 Then ; ===> this line added by Zedna to avoid unwanted looping <=== For $i = 1 To UBound($sites)-1 ;// on the fly created submenu that's why it's an array it loops... If $aMsg[0] = $runsit[$i] Then $runmx = grabLinks($sites[$i][0]) ;rowid $runpname = $sites[$i][1] $dofetch = True GUICtrlSetData($btn_startop, "Pause") elseif $aMsg[0] = $runrefsit[$i] Then local $html = loadPage($sites[$i][2]) ;url $runmx = grabinsertLinks($html, $sites[$i][0]) ;rowid $runpname = $sites[$i][1] $dofetch = True GUICtrlSetData($btn_startop, "Pause") elseif $aMsg[0] = $expsit[$i] Then exportSQL($sites[$i][1]) EndIf Next EndIf EndSwitch Case $frmSiteAdd Switch $aMsg[0] Case $GUI_EVENT_CLOSE GUIDelete($frmSiteAdd) Case $btn_add ;//blablabla waaaaay too long GUIDelete($frmSiteAdd) EndSwitch EndSwitch WEnd Edited April 23, 2018 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted April 23, 2018 Share Posted April 23, 2018 Also look at this partially related Wiki page https://www.autoitscript.com/wiki/Interrupting_a_running_function Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
itsid Posted April 24, 2018 Author Share Posted April 24, 2018 Jeez, not only are you late to the party (problem solved) but why on earth would do you think it'd be important to check non zero first... that loop's too short to cause any significant increase in runtime.. and if it would be relevant, then it'd be better to only check values greater than zero (you know to also ignore button release and such) ... so that's quite a half455 line of code there... luckily it's not important at all (not until you add a couple of hundred menu items which quite frankly is an insane idea anyways) since it's solely the work that caused the issue not the switch case and worst if you'd paid attention, you'd noticed that I solved my problem with the windows message handle .... (a method mentioned in the linked wiki) Also double posting, really? I'm new around here and even I know where that edit button is! 'sid Link to comment Share on other sites More sharing options...
Earthshine Posted April 24, 2018 Share Posted April 24, 2018 (edited) you're not a happy child--are you sid? That member is a really cool member who likes to help others and is generous in giving code. shm Edited April 24, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Zedna Posted April 24, 2018 Share Posted April 24, 2018 (edited) @itsid Such an aggresive reaction is absoltelly inadequate! I have added you to my ignore list and I'm done with you. I'm happy that the most of people on this forum don't behave the way like you ... Edited April 24, 2018 by Zedna Earthshine 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Developers Jos Posted April 24, 2018 Developers Share Posted April 24, 2018 (edited) 7 hours ago, itsid said: Also double posting, really? I'm new around here and even I know where that edit button is! 'sid @itsid, Wonder whether you could tell me what justified your patronizing smart ass response to a member only trying to assist? Try you ignore when you feel it doesn't help you instead off taking the bullying approach, as that will go much further. Jos EDIT: I found a great quote used/made by ... yourself, that could very well apply here: Quote If you don't know why you're here... you might as well leave. Edited April 24, 2018 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 24, 2018 Moderators Share Posted April 24, 2018 (edited) itsid, I agree wholeheartedly with the above comments. Please change your attitude for future posts or you may well find that you will no longer be able to post at all. M23 Edit: Managing to get 2 members of the Moderation team reacting at the same time is usually a sign that you are doing something we regard as pretty OTT - please take note. Edited April 24, 2018 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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