Jump to content

Error : Subscript used with non-Array variable.:


Recommended Posts

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 ?

Link to comment
Share on other sites

  • Developers

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.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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