Reizvoller

Subscript Used on Non-Accessible Variable WinGetPos error

10 posts in this topic

Func workSpaceSetup ()
   ConsoleWrite ("workSpaceSetup" &@CRLF)
   $workSpace = WinGetHandle ("some site - Google Chrome")
   ConsoleWrite ($workSpace&@CRLF)
   $pos1 = WinGetPos ($workSpace)
   WinMove ($workSpace , "", $pos1[0] , $pos1[1] , 1366, 768, 0)
EndFunc
Quote

(26) : ==> Subscript used on non-accessible variable.:
WinMove ($workSpace , "", $pos1[0] , $pos1[1] , 1366, 768, 0)
WinMove ($workSpace , "", $pos1^ ERROR
>Exit code: 1    Time: 0.1179

So the script is first, the error I get is second in the quote.

This is one function of many for an app I am building but it is the first one that runs so I know there aren't other things at play here.

The idea is to keep the window in the same space it is when the script runs but just resize it as this app is used across multiple computers with different screen resolutions.

Could someone please elaborate upon what "Subscript used on non-accessible variable" means? 

Oh and the variable is declared as "Global $pos1 = 0" at the top outside of any functions with the other global variables.

Any advice would be greatly appreciated!

-Reiz

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

https://www.autoitscript.com/autoit3/docs/function_notes.htm

Quote

If a function can set the @error flag, you should always check it before using a return value - if @error indicates an error then the function return value is generally undefined...

@error is always set to 0 when entering in a function.

Example:

Func workSpaceSetup ()
   ConsoleWrite ("workSpaceSetup" &@CRLF)
   $workSpace = WinGetHandle ("some site - Google Chrome")
   If @error then Return SetError(1,0,0)
   
   ConsoleWrite ($workSpace&@CRLF)
   $pos1 = WinGetPos ($workSpace)
   If @error then Return SetError(2,0,0)
   
   WinMove ($workSpace , "", $pos1[0] , $pos1[1] , 1366, 768, 0)
EndFunc

 

EDIT: Your problem was that you not check if this window title exist, and in next step if WinGetPos returns array 

Edited by mLipok
1 person likes this

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Hey,

Thank you for the fantastic information!

I am really grateful for the link and your explanation.

I am up and running happily! :)

-Reiz

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I also get this error regularly with the code (and I am checking for existence):

Func cancelGillickQuestionWindow()

;logMSG("cancelQuestionWindow")
    ; Close the do you want to switch to open (viewing documents) window
    $win1Title = "[TITLE:Question]"
    If  WinExists($win1Title) Then
        $winPos = WinGetPos($win1Title)
        If $winPos[0] = 106 And _
           $winPos[1] = 327 And _
           $winPos[2] = 737 And _
           $winPos[3] = 369 Then
            WinActivate($win1Title)
            Send ( "{ALTDOWN}d{ALTUP}")     ; Defer decision
        EndIf
    EndIf
EndFunc


 

Untitled.jpg.12ab2d1eb3e9913572acae30d03

Edited by dgm5555
deleted return (which wasn't in first code post)

Share this post


Link to post
Share on other sites
4 minutes ago, dgm5555 said:

and I am checking for existence

:blink: Where ?
 

btw:
Please read this:  How to post code on the forum *


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

code posting corrected

the "if winExists" line in the code is checking for existence of window:
 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Try this:

cancelGillickQuestionWindow()
If @error Or @extended Then MsgBox($MB_ICONERROR, 'TEST', '@error = ' & @error & @CRLF & '@extended = ' & @extended)


Func cancelGillickQuestionWindow()
    Return
    ;logMSG("cancelQuestionWindow")
    ; Close the do you want to switch to open (viewing documents) window
    $win1Title = "[TITLE:Question]"
    If Not WinExists($win1Title) Then Return SetError(1, 0, 0)

    $winPos = WinGetPos($win1Title)
    If @error Then Return SetError(2, @error, 0)

    If _
            $winPos[0] = 106 And _
            $winPos[1] = 327 And _
            $winPos[2] = 737 And _
            $winPos[3] = 369 _
             Then
        WinActivate($win1Title)

        Send("{ALTDOWN}d{ALTUP}") ; Defer decision
        Return SetError(0, 1, 1)
    EndIf

    Return SetError(0, 2, 1)
EndFunc   ;==>cancelGillickQuestionWindow

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

:oops:.... fixed. :D Thanks.

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

I do apologise after "fixing" the code posting as per mLipok I pasted my current func which included a return which bypassed it completely (I've now removed the immediate return call)

I've added the edits and integrated your suggestion into my logging system (which will save it to text file), but if I don't get the error in the next hour before I leave work (it's caused by a particular automatic popup window which I can't manually trigger), so I'll post the results here next week.

Thanks for the super-prompt suggestions.

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

  • Similar Content

    • argumentum
      By argumentum
      UDF to intercept the error window of AutoIt, showing more details about the error, including ability to save and send by email!
    • davidacrozier
      By davidacrozier
      I am attempting to drag and drop a file from one windows explorer window to another windows explorer window (henceforth referred to as window1 and window2).  I am not using the web.  I have used autowinexp.au3 (taken from LarsJ's automatewindowsexplorer.au3) to give focus (function GetFileFocus)  to a file on window1.   The problem is that sometimes the file with the focus is not displayed on window1 because it is farther down the list than what is displayed in window1.  There are other ways to accomplish this (like copy and paste) but I want to emulate the GUI doing a drag and drop.  I work as a digital forensicator and my task is to examine what artifacts are left behind on move/copy vs a drag and drop.  Please note that when I open window1 and window2 they are on top of each other, so I drag window2 over about 1150 pixels and that part works great.    
      My code is listed below.  Please understand that I have tried several different methods to accomplish this task.  The last one was to estimate that the top of the window1 header is approximately 320 pixels and to multiply the index of the file by 20 pixels since that appears to be the approximate height of individual files using the AutoIT Windows Info tool.  Ideally the program would search window1 for the file name text and provide a mouse position for it.  Or the program would allow me to scroll to where the file name is located.  Any and all ideas are welcome.
      Using Windows 10
      AutoIT v3.3.14.2
      Thanks!
      DavidaCrozier
      PS Any problems in autowinexp.au3 are mine and not the author of automatewindowsexplorer.au3.  
       
      DragAndDropForum.au3
      autowinexp.au3
    • TrashBoat
      By TrashBoat
      Is this possible:
      Executing a function from an include, but taking the function name from a gui input and then executing that function using the include:
      #include <Something.au3> ;input reads "Tree" $functionName = GuiCtrlRead($input1) $functionName(1) And the include is gonna have
      Func Tree($x) If $x = 1 Then $this = "text" MsgBox(0,$this,"whatever") EndFunc is it possible?
    • SkysLastChance
      By SkysLastChance
      I get this error, Whenever I try to find a date. Does anyone have any idea why? I saw some post from 2015, However I would imagine this is fixed by now. @water
      >"J:\Temporary Files\XXXXXXXXX\AutoIt\AutoIt\AutoIt\SciTe\..\autoit3.exe" /ErrorStdOut "C:\Users\XXXXXX\Desktop\Call Report Automation.au3"     "J:\Temporary Files\XXXXXXXX\AutoIt\AutoIt\AutoIt\Include\Excel.au3" (656) : ==> The requested action with this object has failed.: $aResult[$iIndex][1] = $oMatch.Name.Name $aResult[$iIndex][1] = $oMatch^ ERROR >Exit code: 1    Time: 5.791 #include <Excel.au3> Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,Default,"A2",3) _Excel_RangeWrite ($oExcel1,"Calls Handled",$oRead,"BY7") Sleep (1000) _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92") MsgBox (0,"Test",$oRead) UPDATE:
      If I take out this line it works. By works I mean I don't get the error. :/  However, I need it. I am just confused.
      _Excel_RangeWrite ($oExcel1,"Calls Handled",$oRead,"BY7")  
      UPDATE 2: I also get this error when trying to use the helpfile examples. I have version 3.3.14.2
      \AutoIt\AutoIt\AutoIt\Include\Excel.au3" (670) : ==> The requested action with this object has failed.: $oSheet = $oWorkbook.Sheets($iIndexSheets) $oSheet = $oWorkbook^ ERROR >Exit code: 1 Time: 0.8931  
    • SkysLastChance
      By SkysLastChance
      How would I go about writing a IF Then statement if the conrol send fails?
      Run ("Notepad.exe") WinWaitActive ("Untitled - Notepad") ControlSend("Untitled - Notepad", "", "Edit1", ("Provider Practice Record")) I have been running into lag alot. So my script has been missing input. I would like to be able to have it retry to put in "Provider Practice Record" if it misses. 
      I am assuming  a if then statement is what I need but I am not sure what ControlSend will return if it tries to send to Edit1 and it is not there. 
      Or do I need to just add a timeout?