Sign in to follow this  
Followers 0
AJ6594

Error : Subscript used with non-Array variable.:

3 posts in this topic

Func activate1()

Local $x = WinList(), $position

For $i = 1 to $x[0][0]

$position = WinGetPos($x[$i][1],"")

If $position[1] = 5 Then

WinActivate($x[$i][1],"")

EndIf

Next

EndFunc

this kicks back an error

==> Subscript used with non-Array variable.:

If $position[1] = 5 Then

If $position^ ERROR

What is wrong ?

Share this post


Link to post
Share on other sites



First test if the WinGetPos() was successful by testing for @error=0

Failure: Returns 0 and sets @error to 1 if windows is not found.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Func activate1()

Local $x = WinList(), $position

For $i = 1 to $x[0][0]

$position = WinGetPos($x[$i][1],"")

If $position[1] = 5 Then

WinActivate($x[$i][1],"")

EndIf

Next

EndFunc

this kicks back an error

==> Subscript used with non-Array variable.:

If $position[1] = 5 Then

If $position^ ERROR

What is wrong ?

Works fine for me. Try it like this to see if you get some error reporting:

activate1()

Func activate1()
    Local $x = WinList(), $position
    For $i = 1 To $x[0][0]
        $position = WinGetPos($x[$i][1], "")
        If IsArray($position) Then
            ConsoleWrite("$position[1] = " & $position[1] & @LF)
            If $position[1] = 5 Then
                WinActivate($x[$i][1], "")
            EndIf
        Else
            MsgBox(16, "Error", "$x[" & $i & "][0] = " & $x[$i][0] & @CRLF & _
                    "$x[" & $i & "][1] = " & $x[$i][1] & @CRLF & _
                    "$position = " & $position & "  @error = " & @error)
        EndIf
    Next
EndFunc   ;==>activate1

:)

Edit: Beaten by the Jos-bot!

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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