bremen Posted October 28, 2013 Share Posted October 28, 2013 I am writing a script that updates my inventory with data from an array. There is a possibility that the item might have been used since the item was counted. If this happens I will get and error message. After doing some searching I have found the command "If WinExists" Seems pretty strait forward. What I cant figure out is how to split my script what I am trying to achieve is If Winexists then Close the window, move to the next line in the array, and start the script over again. If it doesnt then keep going. Link to comment Share on other sites More sharing options...
stormbreaker Posted October 28, 2013 Share Posted October 28, 2013 (edited) Global $ARRAY[2] $ARRAY[0] = "Untitled - Notepad" $ARRAY[1] = "Untitled - Notepad" For $i = 0 to (Ubound($ARRAY)-1) ;We loop from 1st to last element of the array If WinExists($ARRAY[$i]) then WinClose($ARRAY[$i]) EndIf NextCan be an example of what ur looking for. Edited October 28, 2013 by MKISH ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
jdelaney Posted October 28, 2013 Share Posted October 28, 2013 In case there are multiple matching windows, for each title: Global $ARRAY[2] $ARRAY[0] = "Your first title" $ARRAY[1] = "Your second title" For $i = 0 to Ubound($ARRAY)-1 While WinExists($ARRAY[$i]) WinClose($ARRAY[$i]) WEnd Next IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
bremen Posted October 28, 2013 Author Share Posted October 28, 2013 expandcollapse popup#include <Array.au3> #include <Excel.au3> ; opens excel workbook ;REST THE WORKBOOK FOR YOUR FILE PATH AND NAME Local $oExcel = _ExcelBookOpen("") ; reads data into array $aArray1 = _ExcelReadSheetToArray($oExcel,1,1,0,2,True) ; closes the excel workbook _ExcelBookClose($oExcel) ; displays the array that was read. _ArrayDisplay($aArray1) ; counts the number of rows in the array $rows = UBound($aArray1) -1 for $c = 1 to $rows WinActivate("") WinWaitActive("") SEND("{ALT}T") Send("{DOWN 2}") SEND("{RIGHT}") Send("{DOWN 2}") Send("{ENTER}") WinWaitActive("") WinActive("") WinWaitActive("") ControlCommand() sleep(700) WinActivate("") ControlClick("") ControlSend(, $aArray1[$c][0]) send("{TAB}") if WinExists("")Then WinActivate("") ControlClick("") WinActive("") WinWaitActive("") ControlClick("") Next Else ControlClick("") sleep(700) ControlClick("") WinWaitActive("") WinActivate("") WinWaitActive("") ControlClick("") WinWaitActive("") WinActivate("") WinWaitActive("") ControlClick("") ControlSend($aArray1[$c][1]) ;;selectes the reason for adjustment ControlCommand("") ControlCommand("") ControlCommand("") ControlClick("") WinWaitActive("") WinActivate("") WinWaitActive("") ControlClick("") WinWaitActive("") WinActive("") WinWaitActive("") ControlClick("") Next endif Here is my code. Unforuntately I had to remove move of the "meat" of the script for security reasons, but what Ia m trying to achieve is in there. Link to comment Share on other sites More sharing options...
jdelaney Posted October 28, 2013 Share Posted October 28, 2013 It's a start. I'd recommend checking that the window state is 'enabled' prior to performing actions...same with the controls. Sometimes scripts can move too quickly, and will cause them to not run successfully. Such as attempting to click a disabled button, that hasn't fully loaded. Before performing clicks, I'd also suggest fousing on the control. Finally, get rid of those sends. There are ways to call menu functions via _guictrlmenu_* WinMenuSelectItem IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
bremen Posted October 28, 2013 Author Share Posted October 28, 2013 Ok I will look into those sugestions. However, it does not address my imediate conceern with the "If Winexists" issue. The script does not run with the way the if staement is entered in. Any Ideas? Link to comment Share on other sites More sharing options...
jdelaney Posted October 28, 2013 Share Posted October 28, 2013 You can't have the if then endif statement with a Next loop in the middle. You need to close the if, prior to the next. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
bremen Posted October 28, 2013 Author Share Posted October 28, 2013 So if I get my error message and I want to go to the next item in my array how do I accoplish that Link to comment Share on other sites More sharing options...
kylomas Posted October 28, 2013 Share Posted October 28, 2013 bremen, Look at "continueloop" in the Help file. 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 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