Sign in to follow this  
Followers 0
Noob

Error: Subscript used with non-Array variable

15 posts in this topic

While 1

$size = WinGetClientSize("Untitled - Notepad")
if $size[0] = 1024 Then MsgBox(0, "", "Hello")

Sleep(100)

WEnd

When I run the above code I get: Error: Subscript used with non-Array variable

My intention is to know when a window is of a certain size (full-size mode, to be exact). But I simplified my code to illustrate how I'm attempting to do it.

Any help would be extremely appreciated, as I've been playing with this for ever a week.

Share this post


Link to post
Share on other sites



My intention is to know when a window is of a certain size (full-size mode, to be exact).

How about using WinGetState instead? Look at the help example.

Share this post


Link to post
Share on other sites

While 1

$size = WinGetClientSize("Untitled - Notepad")
if $size[0] = 1024 Then MsgBox(0, "", "Hello")

Sleep(100)

WEnd

When I run the above code I get: Error: Subscript used with non-Array variable

My intention is to know when a window is of a certain size (full-size mode, to be exact). But I simplified my code to illustrate how I'm attempting to do it.

Any help would be extremely appreciated, as I've been playing with this for ever a week.

If WinGetClientSize() does not find the window, it will NOT return an array. See help file. Check @error to figure out if there was an error!

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

How about using WinGetState instead? Look at the help example.

Joon, my intention is to compare WinGetClientSize("Program Manager") to WinGetClientSize("MyWindow") in order to determine if my window is in full-screen mode. Unfortunatelly the WinGetState function I don't think can tell me if an an application is running in full-screen mode. The Help file says the WinGetState function can tell if a window is maximized, minimized, etc, (but not full-screen mode).

Edited by Noob

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Joon, my intention is to compare WinGetClientSize("Program Manager") to WinGetClientSize("MyWindow") in order to determine if my window is in full-screen mode. Unfortunatelly the WinGetState function I don't think can tell me if an an application is running in full-screen mode. The Help file says the WinGetState function can tell if a window is maximized, minimized, etc, (but not full-screen mode).

First of all why limit yourself to 1 desktop size?

Try

$Ttl = "My Window"
WinWaitActive($Ttl)
$Sz = WinGetPos($Ttl)
If $Sz[2] = @DesktopWidth Then MsgBox(4096,'Winner', "Bet your sweet butt that it's full width")
MsgBox(4096,' Try Again', 'Use @DesktopWidth and $Sz[3]')
If $Sz[2] = @DesktopWidth AND $Sz[3] = @DesktopHeight Then MsgBox(4096,'Wow!!',"It's full screen too')
Have_aDrink()
Exit
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

If WinGetClientSize() does not find the window, it will NOT return an array. See help file. Check @error to figure out if there was an error!

Cheers

Kurt

Kurt, thanks for reply. I tried the script again, and yes, you are right. If WinGetClientSize() does not find the window, then it gives me the error. If the window is active I don't get the error.

So basically I think it is working fine, but I just need to prevent the ERROR from appearing. I'm new to this (and I will most likely stay a noob at this forever), but if someone would be patient enough with me to show me how to turn off the error message (or all error messages) I'd be very grateful. I looked at the @error function in the help file, but it's a bit complicated for me :-(

Share this post


Link to post
Share on other sites

Kurt, thanks for reply. I tried the script again, and yes, you are right. If WinGetClientSize() does not find the window, then it gives me the error. If the window is active I don't get the error.

So basically I think it is working fine, but I just need to prevent the ERROR from appearing. I'm new to this (and I will most likely stay a noob at this forever), but if someone would be patient enough with me to show me how to turn off the error message (or all error messages) I'd be very grateful. I looked at the @error function in the help file, but it's a bit complicated for me :-(

While 1
    $size = WinGetClientSize("Untitled - Notepad")
    If IsArray($size) Then
        If $size[0] = 1024 Then
            MsgBox(0, "", "Hello")
        EndIf
    EndIf
    Sleep(100)
WEnd

You could also check @error after $size = WinGetClientSize("Untitled - Notepad") and use an if statement to proceed if it is an array, or do something else if it isn't


IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

That was his original code ;)

Valuater added IsArray

If IsArray($size) And $size[0] = 1024 Then MsgBox(0, "", "Hello")

Edited by Joon

Share this post


Link to post
Share on other sites

Valuater added IsArray

If IsArray($size) And $size[0] = 1024 Then MsgBox(0, "", "Hello")

Yes, which is all I did. Hence I used the original code?

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

Share this post


Link to post
Share on other sites

"Hello"

lol

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

It works, it works, it works!!!

You guys are the best!!!

Thanks much for all who took the time to reply! I'm looking one-by-one at the code suggestions (and I'm learning new stuff!).

The one that was the easiest for me to implement in my situation was the code suggested by Valuater. It's been added to my little app already, and this was it seems the last piece I needed :-)

Share this post


Link to post
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
Sign in to follow this  
Followers 0