Jump to content

Problem with If statement


Recommended Posts

Hello everyone !

I`m a new guy here and before I decided to add this post I`d read FAQ thouroghly. (My mother tongue is not English so sry for any mistakes in advance).

So the problem is that my script should recognize whether certain window is active or not, if it is active or not then it should run proper function.

At the beginning I`ve declared functions and the root cause is presumably at the bottom of the code and marked with '<-------------'

The code:

$a=0

Func A ()
If Not WinActive("AR System User - [L-Change (Modify)]","L-Change (Modify)") Then WinActivate("AR System User - [L-Change (Modify)]","L-Change (Modify)")
WinWaitActive("AR System User - [L-Change (Modify)]","L-Change (Modify)")
sleep(3000)
MouseMove(1022,204)
MouseDown("left")
MouseUp("left")
MouseMove(386,143)
MouseDown("left")
MouseUp("left")
$a=$a+1
return $a
EndFunc

Func B ()
If Not WinActive("AR System User - Error","OK") Then WinActivate("AR System User - Error","OK")
WinWaitActive("AR System User - Error","OK")
MouseMove(307,25)
MouseDown("left")
MouseUp("left")
sleep(3000)
MouseMove(352,124)
MouseDown("left")
MouseUp("left")
WinWait("AR System User - [L-Change (Modify)]","L-Change (Modify)")
If Not WinActive("AR System User - [L-Change (Modify)]","L-Change (Modify)") Then WinActivate("AR System User - [L-Change (Modify)]","L-Change (Modify)")
WinWaitActive("AR System User - [L-Change (Modify)]","L-Change (Modify)")
MouseMove(1022,204)
MouseDown("left")
MouseUp("left")
MouseMove(386,143)
MouseDown("left")
MouseUp("left")
WinWait("Confirm Save Request ","Do you want to save ")
If Not WinActive("Confirm Save Request ","Do you want to save ") Then WinActivate("Confirm Save Request ","Do you want to save ")
WinWaitActive("Confirm Save Request ","Do you want to save ")
MouseMove(123,16)
MouseDown("left")
MouseMove(122,14)
MouseUp("left")
MouseMove(125,103)
MouseDown("left")
MouseUp("left")
sleep(3000)
$a=$a+1
return $a
EndFunc

do
Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("AR System User - [L-Change (Modify)]","L-Change (Modify)")
If Not WinActive("AR System User - [L-Change (Modify)]","L-Change (Modify)") Then WinActivate("AR System User - [L-Change (Modify)]","L-Change (Modify)")
WinWaitActive("AR System User - [L-Change (Modify)]","L-Change (Modify)")
MouseMove(216,298)
MouseDown("left")
MouseMove(217,298)
MouseUp("left")
MouseMove(204,384)
MouseDown("left")
MouseUp("left")
MouseMove(166,403)
MouseDown("left")
MouseUp("left")
Send("{SHIFTDOWN}c{SHIFTUP}ompleted")
MouseMove(212,706)
MouseDown("left")
MouseUp("left")
MouseMove(272,714)
MouseDown("left")
MouseUp("left")
Send("{ENTER}")
MouseMove(382,718)
MouseDown("left")
MouseMove(383,718)
MouseUp("left")
MouseMove(424,718)
MouseDown("left")
MouseUp("left")
Send("{ENTER}")
MouseMove(892,624)
MouseDown("left")
MouseUp("left")
MouseMove(987,268);'Save'
MouseDown("left")
MouseUp("left")
sleep(4000)

If WinWait("AR System User - [L-Change (Modify)]","L-Change (Modify)") Then A(); <------------------
If WinWait("AR System User - Error","OK") Then B();                                          <------------------
    
until $a=4

So the thing is that sometimes ("AR System User - Error","OK") is not displayed and then my script stops.

Many thanks in advance !

Link to comment
Share on other sites

Sorry i see the ";" and asume that was the error.

If the windows is not displaying then your script is runing but waiting for it, i asume...

Try to set a timeout to the WinWait...

$returnValue = WinWait("AR System User - Error","OK", 10)

If $returnValue = 1 Then B()

wait 10 seconds for the windows an then continue whit the script...

Edited by Chapi
Link to comment
Share on other sites

i think the problem is

If WinWait("AR System User - [L-Change (Modify)]","L-Change (Modify)") Then A(); <------------------
If WinWait("AR System User - Error","OK") Then B();                                          <------------------

your using it in the wrong context...

taken from helpfile... Pauses execution of the script until the requested window exists.

If WinWait("AR System User - [L-Change (Modify)]","L-Change (Modify)") =1 then A()
Edited by Aceguy
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...