Jump to content

WinGetPos non-Array Variable


grakker
 Share

Recommended Posts

I'm having a strange problem. The code I'm using is this:

WinWait ("Sync Status","Close")
$size = WinGetPos ("Sync Status", "Close")
MouseClick ("left", $size[0]+45 , $size[1]+50 ,1,0)

I tried various ControlClick's and whatever, and this is the only way that I have been able to consistently click the control I need. Then again, it's not consistent. Maybe 2/3rds of the time I run the script, it errors out with:

...$size[0]+45....
...$size^ ERROR...
Error: Subscript used with non-Array variable.

Any idea why this is happening? WinGetPos returns an array, and it works sometimes.... Thanks.

Edit: Hmmm....Now it's giving me an error every time....

Edited by grakker
Link to comment
Share on other sites

$size = WinGetPos ("Sync Status", "Close")

If Not @error then

MouseClick ("left", $size[0]+45 , $size[1]+50 ,1,0)

EndIf

<{POST_SNAPBACK}>

OK, This kind of defeats the purpose, as I need to click on the window, otherwise my script errors out.

But this did get me started in the right direction.

I'm not sure why WinGetPos is erroring out on the window title. But I changed the code to

WinWaitActive ("Sync Status","Close")
$size = WinGetPos ("")
MouseClick ("left", $size[0]+45 , $size[1]+50 ,1,0)

And it works. Thanks for the clue.

Link to comment
Share on other sites

Thats not really any better than your code. Now you are guaranteed to get the coordinates for a window, but you are not guaranteed it will be the one you want. Its obviously possible for the window to close or something in the time between WinWaitActive() and the WinGetPos() calls. When this happens, you're going to get the position of the wrong window and start clicking in something you didn't mean to.

this-is-me's code is the correct code. If WinGetPos() sets @error, then something went wrong and your script should not try to click where it should as it won't be clicking in the right window.

Link to comment
Share on other sites

Thats not really any better than your code.  Now you are guaranteed to get the coordinates for a window, but you are not guaranteed it will be the one you want.  Its obviously possible for the window to close or something in the time between WinWaitActive() and the WinGetPos() calls.  When this happens, you're going to get the position of the wrong window and start clicking in something you didn't mean to.

this-is-me's code is the correct code.  If WinGetPos() sets @error, then something went wrong and your script should not try to click where it should as it won't be clicking in the right window.

<{POST_SNAPBACK}>

Perhaps, albeit in a very pedantic way. It seems that AutoIt doesn't play well sometimes unless I'm using explorer for my shell. Which I don't. If my choices is between always erroring out on WinGetPos(), or taking the 1 in some-big-number chance that some window may open or close in the fraction of a second between the WinWaitActive call and the click my script sends, I'll take the later.

Why WinWaitActive("Sync Status", "Close") works and right afterwards WinGetPos("Sync Status", "Close") errors, I don't understand, unless it's related to my using a different shell. But at this point it works and I'm moving on.

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...