Jump to content

If statement


bremen
 Share

Recommended Posts

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

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
Next
Can be an example of what ur looking for. Edited 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

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

#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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...