hiepkhachsg Posted March 4, 2016 Share Posted March 4, 2016 Hi all. I'm newbie. With many try, i have the problems with loop such as For ... to ... next, while ... wend, ... I found that when a loop is doing, everything (such as gui even, control even, others func() ...) must be waitting until it finished to work. With a long time loop, everything will continue after a long time it finished. I wonder why there is a first loop (While 1 | Sleep(1000) | WEnd) to keep the GUI always on, everything can work simultaneously with it. But when have the second loop is running, everything can't work at the same time with the second. How can i solve this problems. Tks in advance. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 4, 2016 Moderators Share Posted March 4, 2016 (edited) hiepkhachsg, You should only need a Sleep(10) in your idle loop to keep the script alive - but quite what else is going wrong is impossible to say without seeing the script itself. So I suggest you post it - see here how to do it - so we can take a look. M23 Edited March 4, 2016 by Melba23 Typo 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...
AutoBert Posted March 4, 2016 Share Posted March 4, 2016 As you can see in this script: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $gui = GUICreate("KLeines 1 X 1", 400, 120) $Start = GUICtrlCreateButton("&Start", 10, 10) $PauseResume = GUICtrlCreateButton("&Pause", 10, 40) $Anzeige = GUICtrlCreateLabel("Anzeige", 10, 90, 380) GUISetState() While 1 _EventHandler() WEnd Func _EventHandler() $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $Start GUICtrlSetState($Start, $GUI_DISABLE) For $i = 1 To 10 For $j = 1 To 10 GUICtrlSetData($Anzeige, $j & " * " & $i & " = " & $i * $j) _MySleep(500) Next Next GUICtrlSetState($Start, $GUI_ENABLE) Case $PauseResume If GUICtrlRead($PauseResume) = "&Pause" Then GUICtrlSetData($PauseResume, "&Weiter") While GUICtrlRead($PauseResume) <> "&Pause" _MySleep(50) WEnd Else GUICtrlSetData($PauseResume, "&Pause") EndIf EndSwitch EndFunc ;==>_EventHandler Func _MySleep($iMSec) Local $iStart = TimerInit() Do _EventHandler() Until TimerDiff($iStart) >= $iMSec EndFunc ;==>_MySleep it's possible that script is working and the buttons also working when specific Msg is fired. But this technique will not proberly work with MsgBoxes or RunWait, ShellExecuteWait and other functions you couldn't split in small pieces. So i full ack with M23, post your script. Link to comment Share on other sites More sharing options...
hiepkhachsg Posted March 4, 2016 Author Share Posted March 4, 2016 I write a litte example to describe for my loop problem here. Generally, we can click button Close and exit at any time. But when a 2nd loop is running, we click button Close and must wait the loop finished to exit. #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("guioneventmode",1) GUICreate("Loop Problem", 200, 200, 192, 124) GUICtrlCreateButton("Close", 72, 152, 75, 25) GUICtrlSetOnEvent(-1,"close") GUICtrlCreateButton("Run 2nd Loop", 72, 56, 75, 65) GUICtrlSetOnEvent(-1,"runloop") $idLabel = GUICtrlCreateLabel("0", 72, 24, 74, 17) GUISetState(@SW_SHOW) while 1 Sleep(10) WEnd Func runloop() For $i=1 to 100000 GUICtrlSetData($idLabel,$i) $i+=1 Sleep(10) Next EndFunc Func close() Exit EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 4, 2016 Moderators Share Posted March 4, 2016 hiepkhachsg, I thought that might be the problem. The Interrupting a running function tutorial in the Wiki explains why this happens and how you can get around it. Come back if you still have problems after having read the tutorial. M23 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...
AutoBert Posted March 4, 2016 Share Posted March 4, 2016 (edited) A method not explained in wiki, building a pseudoloop with Adlib: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("guioneventmode",1) GUICreate("Loop Problem", 200, 200, 192, 124) GUICtrlCreateButton("Close", 72, 152, 75, 25) GUICtrlSetOnEvent(-1,"close") GUICtrlCreateButton("Run 2nd Loop", 72, 56, 75, 65) GUICtrlSetOnEvent(-1,"startloop") $idLabel = GUICtrlCreateLabel("0", 72, 24, 74, 17) GUISetState(@SW_SHOW) while 1 Sleep(10) WEnd Func startloop() AdlibRegister('runloop',10) EndFunc Func runloop() Local Static $i=1 If $i<100001 Then GUICtrlSetData($idLabel,$i) $i+=1 else $i=1 AdlibUnRegister('runloop') EndIf EndFunc Func close() AdlibUnRegister('runloop') Exit EndFunc Edited March 4, 2016 by AutoBert Link to comment Share on other sites More sharing options...
hiepkhachsg Posted March 5, 2016 Author Share Posted March 5, 2016 Tks Melba23 and AutoBert. The AutoBert's method may be a solution. Tks. 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