Jump to content

How to suppress "Subscript used on non-accessible variable"


Recommended Posts

I'm a beginner to Autoit and using other forms and help guides I was able to create the following script that applies a layer to Opera's "X" box to prevent it from being closed. The script does execute without errors till I close out Opera which returns the following error as indicated by the attached picture. Please can someone help me fix the error? Thanks!

Code:

#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUICloseOnESC", 0)

$iLast_X = 0
$iLast_Y = 0

Run("C:\Program Files\Opera beta\launcher.exe")
WinWaitActive("Speed Dial - Opera")

$hOpera_Handle = WinGetHandle("Speed Dial - Opera")

$hGUI = GUICreate("My [X]", 50,22, -1, -1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
$hPic = GUICtrlCreateLabel("        X", 0, 0, 40, 30)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hPic
            Run ("C:\Program Files\Opera beta\launcher.exe")
    EndSwitch

    Local $aOpera_Pos = WinGetPos($hOpera_Handle)
    If $aOpera_Pos[0] <> $iLast_X Or $aOpera_Pos[1] <> $iLast_Y Then
        $iLast_X = $aOpera_Pos[0]
        $iLast_Y = $aOpera_Pos[1]
        WinMove($hGUI, '', $aOpera_Pos[0] + $aOpera_Pos[2] - 55, $aOpera_Pos[1])
     EndIf
  WEnd

 

OperaScript_error.PNG

Link to comment
Share on other sites

Add a check prior to the if statement using the array:

Local $aOpera_Pos = WinGetPos($hOpera_Handle)
    If IsArray($aOpera_Pos) Then
        If $aOpera_Pos[0] <> $iLast_X Or $aOpera_Pos[1] <> $iLast_Y Then
            $iLast_X = $aOpera_Pos[0]
            $iLast_Y = $aOpera_Pos[1]
            WinMove($hGUI, '', $aOpera_Pos[0] + $aOpera_Pos[2] - 55, $aOpera_Pos[1])
        EndIf
    EndIf

Or like this:

Local $aOpera_Pos = WinGetPos($hOpera_Handle)
    If IsArray($aOpera_Pos) And $aOpera_Pos[0] <> $iLast_X Or $aOpera_Pos[1] <> $iLast_Y Then
        $iLast_X = $aOpera_Pos[0]
        $iLast_Y = $aOpera_Pos[1]
        WinMove($hGUI, '', $aOpera_Pos[0] + $aOpera_Pos[2] - 55, $aOpera_Pos[1])
    EndIf

 

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...