Khoneini Posted March 21, 2013 Posted March 21, 2013 (edited) All, I've a question about my script. Mainly about the following part of my code: AUTOITSETOPTION("SendKeyDelay",100) ;SET KEY DELAY IF WINEXISTS("Microsoft Dynamics GP")=1 THEN ;CHECK IF GP IS RUNNING WINACTIVATE("Microsoft Dynamics GP") ;ACTIVATE GP WINDOW SEND("!ans{ENTER}") ;OPEN INVENTORY SERIES POSTING WINDOW SLEEP(5000) ;WAIT 5 SECONDS TO LET THE INVENTORY SERIES POSTING WINDOW OPEN CONTROLFOCUS("Microsoft Dynamics GP","","Button8") ;SELECT "MARK WMS BCHS" Button CONTROLCLICK("Microsoft Dynamics GP","","Button8") ;CLICK "MARK WMS BCHS" Button ;CLICK CANCEL ON REPORT DESTINATION WINDOWS WINWAITACTIVE("Report Destination","",10) CONTROLFOCUS("Report Destination","","Button7") CONTROLCLICK("Report Destination","","Button7") WINWAITACTIVE("Report Destination","",10) CONTROLFOCUS("Report Destination","","Button7") CONTROLCLICK("Report Destination","","Button7") WINWAITACTIVE("Report Destination","",10) CONTROLFOCUS("Report Destination","","Button7") CONTROLCLICK("Report Destination","","Button7") WINWAITACTIVE("Report Destination","",10) CONTROLFOCUS("Report Destination","","Button7") CONTROLCLICK("Report Destination","","Button7") WINWAITACTIVE("Report Destination","",10) CONTROLFOCUS("Report Destination","","Button7") CONTROLCLICK("Report Destination","","Button7") WINWAITACTIVE("Report Destination","",10) CONTROLFOCUS("Report Destination","","Button7") CONTROLCLICK("Report Destination","","Button7") WINWAITACTIVE("Report Destination","",10) CONTROLFOCUS("Report Destination","","Button7") CONTROLCLICK("Report Destination","","Button7") WINWAITACTIVE("Report Destination","",10) CONTROLFOCUS("Report Destination","","Button7") CONTROLCLICK("Report Destination","","Button7") ELSE ;IF GP IS NOT RUNNING BELOW CODE WILL BE EXECUTED Instead of having 23 lines of code to only click a cancel button I should also be able to great a loop. When it runs the script and after it clicked "Button8" it should start the loop and keep scanning if the window with the name "Report Destination" pops up and if so it should press "Button7". I'm not sure if we can build in some sort of timeout that if the screen didn't popup for 10 seconds it will go out of the loop and wait until the script gets executed again(we don't want a loop that will eat up all CPU). I've no idea if this is possible with AutoIT and it would be great if someone can help me to get some better understanding of what the capabilities are of creating a loop. I was thinking of a another If / Else statement but this is probably not the "best" solution.. Thanks, Edited March 21, 2013 by Khoneini
Moderators Melba23 Posted March 21, 2013 Moderators Posted March 21, 2013 Khoneini, How many times are you expecting a "Report Destination" dialog to appear? At the moment you are waiting 8 times for 10 seconds which seems a bit OTT unless you will have that many. I would suggest something like this might suit you better: AutoItSetOption("SendKeyDelay", 100) ;SET KEY DELAY If WinExists("Microsoft Dynamics GP") = 1 Then ;CHECK IF GP IS RUNNING WinActivate("Microsoft Dynamics GP") ;ACTIVATE GP WINDOW Send("!ans{ENTER}") ;OPEN INVENTORY SERIES POSTING WINDOW Sleep(5000) ;WAIT 5 SECONDS TO LET THE INVENTORY SERIES POSTING WINDOW OPEN ControlFocus("Microsoft Dynamics GP", "", "Button8") ;SELECT "MARK WMS BCHS" Button ControlClick("Microsoft Dynamics GP", "", "Button8") ;CLICK "MARK WMS BCHS" Button ;CLICK CANCEL ON REPORT DESTINATION WINDOWS ; Get a timestamp $iBegin = TimerInit() ; Start a loop Do ; Look for the dialog If WinExists("Report Destination") Then ; If found then close it WinActivate("Report Destination") ControlFocus("Report Destination", "", "Button7") ControlClick("Report Destination", "", "Button7") EndIf ; Give the CPU a breather Sleep(10) Until TimerDiff($iBegin) > 10 * 1000 ; Keep looping until 10 secs have elapsed Else ;IF GP IS NOT RUNNING BELOW CODE WILL BE EXECUTED What do you think? 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
Khoneini Posted March 21, 2013 Author Posted March 21, 2013 (edited) Looks good to me at least something to test. Everytime I expect the "Report Destination" dialog appear for 4 times. Maybe it would be just better to instead of letting the loop run for 10 seconds, just let it go through the loop 5 times(1 more time in case it did miss 1 dialog). OR letting it loop until it doesn't find another "Report Destination" dialog anymore. These dialogs are popping up right after you close one down. What I'm trying to achieve is a more efficient code where I can relay on instead of what we're having now. Your input is really appreciated thanks! Edited March 21, 2013 by Khoneini
Moderators Melba23 Posted March 21, 2013 Moderators Posted March 21, 2013 Khoneini,If you are expecting 4 dialogs then this would be a better solution:;CLICK CANCEL ON REPORT DESTINATION WINDOWS ; We expect 4 dialogs $iDialog_Count = 0 ; Start an infinite loop While 1 ; Look for the dialog If WinExists("Report Destination") Then ; If found then close it WinActivate("Report Destination") ControlFocus("Report Destination", "", "Button7") ControlClick("Report Destination", "", "Button7") ; We closed a dialog, so increase the count $iDialog_Count +=1 ; Have we closed all 4? If $iDialog_Count = 4 Then ; Yes, so exit ExitLoop EndIf EndIf ; Give the CPU a breather Sleep(10) WEndIf you would still like an overall time limit so that you do not hang around if there are fewer than 4 for some reason, then you could use the Do...Until loop from the last suggestion in place of the While...WEnd loop here. Do ask if you need a hand amalgamating the 2 scripts. 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
Khoneini Posted March 21, 2013 Author Posted March 21, 2013 (edited) I can't thank you enough for this! I'm still identifying the process but it looks like it is not always 4 times. Sometimes it is also 6 times or even 8 times that the dialog pops up. It is always right after "Button8" is being pressed so we can start the loop after that. Which resolution do you advice in this situation? Just let the loop run for 10-15 seconds or let the loop run for X times? Edited March 21, 2013 by Khoneini
Moderators Melba23 Posted March 21, 2013 Moderators Posted March 21, 2013 Khoneini,As you have no idea how many dialogs you will have to cancel, using a count is not a good idea. So I suggest you wait for a certain time after cancelling each dialog to see if another pops up - if nothing appears after that time then you can continue:;CLICK CANCEL ON REPORT DESTINATION WINDOWS ; Get a timestamp $iBegin = TimerInit() ; Start a loop Do ; Look for the dialog If WinExists("Report Destination") Then ; If found then close it WinActivate("Report Destination") ControlFocus("Report Destination", "", "Button7") ControlClick("Report Destination", "", "Button7") ; Reset the timestamp $iBegin = TimerInit() EndIf ; Give the CPU a breather Sleep(10) ; Exit the loop if we go 15 secs without cancelling a dialog Until TimerDiff($iBegin) > 15 * 1000How does that sound? M23P.S. When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unneccessarily. 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
Khoneini Posted March 21, 2013 Author Posted March 21, 2013 (edited) Sorry about Quoting your posts. I think this will be the solution. Will try this and let you know if it's working or not! There is one more thing that frustrates me and that is the first part of the script. It doesn't need to fre-open the INVENTORY SERIES POSTING WINDOW time after time so I think it would be the best to put this in a Function: SEND("!ans{ENTER}") ;OPEN INVENTORY SERIES POSTING WINDOW And only execute IF the Inventory Series Posting window is not open. The CONTROL attributes of this window are: expandcollapse popup>>>> Window <<<< Title: Microsoft Dynamics GP Class: TNTMAIN Position: -4, -4 Size: 1032, 748 Style: 0x17CF0000 ExStyle: 0x00000100 Handle: 0x0004036C >>>> Control <<<< Class: TNT Instance: 1 ClassnameNN: TNT1 Name: Advanced (Class): [CLASS:TNT; INSTANCE:1] ID: 10002 Text: .Inventory Series Posting. Position: 187, 110 Size: 620, 362 ControlClick Coords: 319, 14 Style: 0x56CF0000 ExStyle: 0x00000140 Handle: 0x01780512 >>>> Mouse <<<< Position: 506, 162 Cursor ID: 0 Color: 0x848284 >>>> StatusBar <<<< >>>> ToolsBar <<<< >>>> Visible Text <<<< Dexterity Runtime .Inventory Series Posting. &Post Redispla&y Mark &All U&nmark All Mark WMS Bchs Toolbar The reason why I would like to put this in a function is because it might need to be executed somewhere else in the script too(in the ELSE statement at the bottom of my script) The problem why I'm unable to do this myself is because I do understand the WINACTIVATE, WINEXISTS and WINWAITACTIVE command. Although I'm not sure what to use if we need to filter on: Text: .Inventory Series Posting. and/or ID: 10002 Hmm, might be that I already found my solution, just curious if it would be advisible to have a IF statement within a IF statement. So between IF WINEXISTS("Microsoft Dynamics GP")=1 THEN ;CHECK IF GP IS RUNNING AND ELSE ;IF GP IS NOT RUNNING BELOW CODE WILL BE EXECUTED I'll add the following: AUTOITSETOPTION("SendKeyDelay",100) ;SET KEY DELAY IF WINEXISTS("Microsoft Dynamics GP")=1 THEN ;CHECK IF GP IS RUNNING WINACTIVATE("Microsoft Dynamics GP") ;ACTIVATE GP WINDOW IF WINEXISTS("Microsoft Dynamics GP", ".Inventory Series Posting.")=0 THEN SEND("!ans{ENTER}") ;OPEN INVENTORY SERIES POSTING WINDOW WINWAITACTIVE("Microsoft Dynamics GP", ".Inventory Series Posting.",30) ELSE CONTROLFOCUS("Microsoft Dynamics GP","","Button8") ;SELECT "MARK WMS BCHS" Button CONTROLCLICK("Microsoft Dynamics GP","","Button8") ;CLICK "MARK WMS BCHS" Button ;CLICK CANCEL ON REPORT DESTINATION WINDOWS $iBegin = TimerInit() ;GET A TIMESTAMP FOR THE LOOP DO ;START THE LOOP IF WINEXISTS("Report Destination") THEN ;LOOK FOR THE DIALOG WINACTIVATE("Report Destination") ;ACTIVATE REPORT DESTINATION WINDOW CONTROLFOCUS("Report Destination", "", "Button7") ;SELECT "CANCEL" Button CONTROLCLICK("Report Destination", "", "Button7") ;CLICK "CANCEL" Button $iBegin = TimerInit() ;RESET THE TIMESTAMP SO IT WILL START THE LOOP AGAIN ENDIF SLEEP(10) ;GIVE THE CPU A BREATHER UNTIL TimerDiff($iBegin) > 5 * 1000 ; EXIT THE LOOP IF WE GO 5 SECS WITHOUT CANCELLING A DIALOG ELSE ;IF GP IS NOT RUNNING BELOW CODE WILL BE EXECUTED Can someone please let me know if above code is correct? Thanks a million for all the help provided. Edited March 21, 2013 by Khoneini
Moderators Melba23 Posted March 21, 2013 Moderators Posted March 21, 2013 Khoneini,I think your logic is a bit flawed in that snippet - does this amended version make sense to you? AutoItSetOption("SendKeyDelay", 100) ;SET KEY DELAY If WinExists("Microsoft Dynamics GP") = 1 Then ;CHECK IF GP IS RUNNING ; Check if INVENTORY SERIES POSTING WINDOW is open If Not WinExists("Microsoft Dynamics GP", ".Inventory Series Posting.") Then Send("!ans{ENTER}") ;OPEN INVENTORY SERIES POSTING WINDOW ; And wait for it to appear WinWait("Microsoft Dynamics GP", ".Inventory Series Posting.", 30) EndIf ; Now activate main window WinActivate("Microsoft Dynamics GP") ;ACTIVATE GP WINDOW ControlFocus("Microsoft Dynamics GP", "", "Button8") ;SELECT "MARK WMS BCHS" Button ControlClick("Microsoft Dynamics GP", "", "Button8") ;CLICK "MARK WMS BCHS" Button ;CLICK CANCEL ON REPORT DESTINATION WINDOWS $iBegin = TimerInit() ;GET A TIMESTAMP FOR THE LOOP Do ;START THE LOOP If WinExists("Report Destination") Then ;LOOK FOR THE DIALOG WinActivate("Report Destination") ;ACTIVATE REPORT DESTINATION WINDOW ControlFocus("Report Destination", "", "Button7") ;SELECT "CANCEL" Button ControlClick("Report Destination", "", "Button7") ;CLICK "CANCEL" Button $iBegin = TimerInit() ;RESET THE TIMESTAMP SO IT WILL START THE LOOP AGAIN EndIf Sleep(10) ;GIVE THE CPU A BREATHER Until TimerDiff($iBegin) > 5 * 1000 ; EXIT THE LOOP IF WE GO 5 SECS WITHOUT CANCELLING A DIALOG Else ;IF GP IS NOT RUNNING BELOW CODE WILL BE EXECUTED EndIfAs to making a function of the opening Inventory Series Posting code - how many times will you call it in the script? It is only 2 lines - and you need at least one to call a function! Quite frankly I would leave it as it is until you get the whole script running as you wish - then you can try and optimise further. Premature optimisation is never a good idea - get it working first!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
aleph01 Posted March 21, 2013 Posted March 21, 2013 This is only tangentially related to this thread, no offense intended. The original code had a lot of ControFocus commands before the ControlClicks. Is there a time when this is helpful? Doesn't ControlClick send a click to a control regardless of focus? Do I need to start using ControlFocus commands prior to my ControlClicks? Thanks for any reply. Meds. They're not just for breakfast anymore.
BrewManNH Posted March 21, 2013 Posted March 21, 2013 You only need to use ControlFocus if the application requires the control or window to have focus before it accepts the command you send it. If you (your application) don't need it, then you don't need to use it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
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